In this lab, you will create a new repository in GitLab and configure it in AWS Cloud9. Next, you will create the source code of the demo app and commit it into the repository.
echo GitLabURL = $GitLabURL
echo GitLabPassword = $GitLabPassword
root
and the password from GitLabPassword output value.Challenge: If you are familiar with GitLab, then test your knowledge by creating a new empty private repository called GitLab Spot Workshop
.
GitLab Spot Workshop
, in the dropdown next to Project URL select root
user, and unmark the checkbox Initialize repository with a README. Leave the rest values as default, and choose Create project:https://xxx.cloudfront.net/root/gitlab-spot-workshop.git
) that is displayed, for example, in Create a new repository section on the screen.You will now initialize Git repository in the demo app and add your GitLab environment as an origin to it.
cd ~/environment/amazon-ec2-spot-cicd-workshop/gitlab-spot/demo-app/
ECR_ADDRESS
and other placeholders with their actual values (like the address of ECR repository created in the CloudFormation stack) and save it into .gitlab-ci.yml
file as expected by GitLab CI/CD:TOKEN=$(curl -s -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 600")
REGION=$(curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/placement/region)
export ECR_INFO=$(aws ecr describe-repositories --region $REGION --query "repositories[?contains(repositoryName, 'gitlab-spot-demo')].repositoryUri" --output text)
export ECR_ADDRESS=$(echo $ECR_INFO | awk -F'/' '{print $1}')
export ECR_NAME=$(echo $ECR_INFO | awk -F'/' '{print $2}')
sed "s/\${ECR_ADDRESS}/${ECR_ADDRESS}/g" template-gitlab-ci.yml | sed "s/\${ECR_NAME}/${ECR_NAME}/g" | sed "s/\${AWS_REGION}/${REGION}/g" > .gitlab-ci.yml
amazon-ec2-spot-cicd-workshop/gitlab-spot/demo-app/.gitlab-ci.yml
(if you don’t see it, make sure you have enabled the hidden files in Workshop Preparation). Look through it to understand what it does.Your Name
and youremail@test.tld
with the values you prefer):git config --global user.name "Your Name"
git config --global user.email "youremail@test.tld"
git config --global credential.helper store
git init --initial-branch=main
git remote add origin https://xxx.cloudfront.net/root/gitlab-spot-workshop.git
git add .
git commit -m "Initial commit"
You are now ready to do the key step in configuring GitLab CI/CD on Spot instances: add the runners. Please proceed to Configure GitLab runners on Spot instances.