Skip to content

Instantly share code, notes, and snippets.

@agowa
Last active May 7, 2019 17:31
Show Gist options
  • Save agowa/4f6a5e7bde65a0ad528b936047d49e28 to your computer and use it in GitHub Desktop.
Save agowa/4f6a5e7bde65a0ad528b936047d49e28 to your computer and use it in GitHub Desktop.
gitlab-runner within docker systemd unit
[Unit]
Description=Cleanup and update docker image.
After=network.target docker.service
Requires=network.target docker.service
[Service]
ExecStartPre=/usr/bin/docker container prune -f
ExecStartPre=/usr/bin/docker image prune -f
ExecStartPre=/usr/bin/docker volume prune -f
ExecStartPre=/usr/bin/docker network prune -f
ExecStartPre=/usr/bin/docker system prune -f
ExecStart=/bin/sh -c 'docker image ls --format "{{.Repository}}:{{.Tag}}" | xargs -rI Y docker pull Y'
Type=oneshot
[Install]
WantedBy=multi-user.target
version: '3.6'
services:
runner:
image: gitlab/gitlab-runner:alpine
restart: always
volumes:
- type: tmpfs
target: /home/gitlab-runner
consistency: delegated
- /var/run/docker.sock:/var/run/docker.sock:rw
- ./etc:/etc/gitlab-runner:ro
[Unit]
Description=Restart gitlab-runner service
[Service]
Type=oneshot
ExecStart=/usr/bin/systemctl try-restart gitlab-runner.service
[Unit]
Description=Restart gitlab-runner service to stay up2date
[Timer]
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.target
[Unit]
Description=Start gitlab-runner
Requires=docker-clean.service
[Service]
WorkingDirectory=/srv/gitlab-runner
ExecStart=/usr/bin/docker-compose up --force-recreate
ExecStop=/usr/bin/docker-compose stop
Type=exec
Restart=always
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment