I've been battling with this problem for hours and can't seem to find a solution. I have a self hosted gitlab-runner that's an Amazon Linux 2 EC2 instance. I installed git, docker and gitlab-runner (and registered it successfully). Here's my .gitlab-ci.yml
file:
- install
- lint
- build-nodejs-app
- test
- build-docker-image
install_dependencies:
image: node:15.6.0-alpine
stage: install
script:
- npm install
format:
image: node:15.6.0-alpine
stage: lint
script:
- npm install --global prettier
- prettier --write .
lint:
image: node:15.6.0-alpine
stage: lint
script:
- npm run lint
build:
image: node:15.6.0-alpine
stage: build-nodejs-app
script:
- npm install
- npm run build
artifacts:
paths:
- build/
test_index_file:
image: node:15.6.0-alpine
stage: test
script:
- test -f build/index.html
unit_tests:
image: node:15.6.0-alpine
stage: test
script:
- npm install
- npm run test
build-docker-image-aws:
image: docker:stable
services:
- docker:dind
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_TLS_CERTDIR: ""
stage: build-docker-image
before_script:
- mkdir -p ~/.aws
- echo $AWS_ACCESS_KEY_ID > ~/.aws/credentials
- echo $AWS_SECRET_ACCESS_KEY >> ~/.aws/credentials
script:
- docker info
- docker login -u $DOCKERHUB_USERNAME -p $DOCKERHUB_PASSWORD
- cp -R build/ app/
- docker build -t $DOCKER_IMAGE_NAME .
- docker push $DOCKER_IMAGE_NAME
- docker run --rm -v ~/.aws:/root/.aws amazon/aws-cli ecs update-service --cluster $ECS_CLUSTER --service $ECS_SERVICE --force-new-deployment
dependencies:
- build
Trying to build a node.js app, have the artifact pushed to docker to build an image and then deployed to AWS with Terraform (I'll integrate the Terraform part later). After toiling to get the right config for the gitlab-ci file, this is one brick wall I can't seem to get past.
This is the error I get:
$ echo $AWS_ACCESS_KEY_ID > ~/.aws/credentials
$ echo $AWS_SECRET_ACCESS_KEY >> ~/.aws/credentials
$ docker info
Client:
Debug Mode: false
Server:
ERROR: Cannot connect to the Docker daemon at [MASKED]. Is the docker daemon running?
errors pretty printing info
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1
I've added both ec2-user and gitlab-runner to docker group and successfully ran docker run hello-world
on both.
sudo service docker status
says it's running but sudo service --status-all
gives this output:
● cfn-hup.service - SYSV: Runs user-specified actions when a
Loaded: loaded (/etc/rc.d/init.d/cfn-hup; bad; vendor preset: disabled)
Active: inactive (dead)
Docs: man:systemd-sysv-generator(8)
netconsole module not loaded
Configured devices:
lo eth0
Currently active devices:
lo eth0 docker0
The sudo systemctl status docker.socket
also says 'active'.
Here's my /etc/gitlab-runner/config.toml
[[runners]]
name = "My Runner"
url = "https://gitlab.com/"
id = 0
token = REDACTED
token_obtained_at = 0001-01-01T00:00:00Z
token_expires_at = 0001-01-01T00:00:00Z
executor = "docker"
[runners.cache]
MaxUploadedArchiveSize = 0
[runners.docker]
tls_verify = false
image = "ubuntu:latest"
privileged = true
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
volumes = ["/var/run/docker.sock:/var/run/docker.sock","/opt/gitlab-runner/cache:/cache:rw"]
shm_size = 0
[[runners]]
name = "Runner on AWS EC2"
url = "https://gitlab.com/"
Feel like I'm going in circles at this point. I'd appreciate any suggestions.