aws-samples / amazon-ec2-gitlab-runner

This repository contains code to deploy and manage Gitlab Runners on Amazon EC2.
MIT No Attribution
58 stars 35 forks source link

CloudFormation Stack fails while creating Autoscaling Group #13

Open smitopher opened 1 year ago

smitopher commented 1 year ago

The Stack fails with a timeout while creating the auto-scaling group The role back deletes all logs preventing diagnoses of problem

miguel-aws commented 1 year ago

Building on this...

In gitlab-runner.yaml:

            09ConfigureDockerExecutor:
              command: !Sub 
                - |
                  for GitlabGroupToken in `aws ssm get-parameters --names /${AWS::StackName}/ci-tokens --query 'Parameters[0].Value' | sed -e "s/\"//g" | sed "s/,/ /g"`;do
                      sudo gitlab-runner register \
                      --non-interactive \
                      --url "${GitlabServerURL}" \
                      --registration-token $GitlabGroupToken \
                      --executor "docker" \
                      --docker-image "${DockerImagePath}" \
                      --description "Gitlab Runner with Docker Executor" \
                      --locked="${isLOCKED}" --access-level "${ACCESS}" \
                      --docker-volumes "/var/run/docker.sock:/var/run/docker.sock" \
                      --tag-list "${RunnerEnvironment}-${RunnerVersion}-docker"
                  done
                - isLOCKED: !FindInMap [GitlabRunnerRegisterOptionsMap, !Ref RunnerEnvironment, isLOCKED]
                  ACCESS: !FindInMap [GitlabRunnerRegisterOptionsMap, !Ref RunnerEnvironment, ACCESS]

cfn-init tries to register GitLab runner using gitlab-runner register command but fails with:

/var/log/cfn-init.log

FATAL: Runner configuration other than name and executor configuration is reserved and cannot be specified when registering with a runner token. This configuration is specified on the GitLab server. Please try again without specifying those arguments.

Because this command fails, the EC2 instance does not send back signal to CFN ASG, causing the stack to rollback:

/var/log/cloud-init-output.log

[   45.675702] cloud-init[1751]: Error occurred during build: Command 09ConfigureDockerExecutor failed
[   45.720475] cloud-init[1751]: 2023-07-06 14:18:25,864 - cc_scripts_user.py[WARNING]: Failed to run module scripts-user (scripts in /var/lib/cloud/instance/scripts)
[   45.728016] cloud-init[1751]: 2023-07-06 14:18:25,872 - [util.py ](http://util.py/)[WARNING]: Running module scripts-user (<module '[cloudinit.config.cc ](http://cloudinit.config.cc/)_scripts_user' from '/usr/lib/python3.9/site-packages/cloudinit/config/cc_scripts_user.py'>) failed

Attempts to resolve

Tried removing --registration-token $GitlabGroupToken but failed:

PANIC: The registration token needs to be entered

Also tried removing --executor "docker", failed:

FATAL: Runner configuration other than name and executor configuration is reserved and cannot be specified when registering with a runner token. This configuration is specified on the GitLab server. Please try again without specifying those arguments.

Instance information

AMI

Type

Region

qisylvia commented 1 year ago

The issue is related to this breaking change in GitLab: https://gitlab.com/gitlab-org/gitlab/-/issues/380872 I have updated the readme to add a link to a vendor supported solution.