Skip to content

Instantly share code, notes, and snippets.

@blackandred
Created November 27, 2017 07:52
Show Gist options
  • Save blackandred/17c2a384ad56e5de1248ff0afb7f5a72 to your computer and use it in GitHub Desktop.
Save blackandred/17c2a384ad56e5de1248ff0afb7f5a72 to your computer and use it in GitHub Desktop.
Ansible: Own docker registry (ARM)

Docker Registry

Creates a docker registry for storing built images.

- name: Create required directory /deploy/registry
become: yes
file:
path: /deploy/registry
state: directory
- name: Install htpasswd tool
become: yes
apt:
name: apache2-utils
state: installed
- name: Copy configuration files
become: yes
template:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
with_items:
- { src: "docker-compose.yml.j2", dest: "/deploy/registry/docker-compose.yml" }
- { src: "restart.sh", dest: "/deploy/registry/restart.sh" }
- { src: "stop.sh", dest: "/deploy/registry/stop.sh" }
- { src: "registry.service", dest: "/lib/systemd/system/registry.service" }
- name: Add executable permissions for restart.sh and stop.sh
become: yes
file: dest="/deploy/registry/{{ item }}" mode=a+x
with_items:
- "restart.sh"
- "stop.sh"
- name: Generate basic auth password
become: yes
shell: "htpasswd -c -b /deploy/registry/htpasswd '{{ REGISTRY_LOGIN }}' '{{ REGISTRY_PASSWORD }}'"
- name: Enable systemd entry and run the service
become: yes
systemd:
name: registry
enabled: yes
state: restarted
version: '2.0'
services:
registry:
#restart: always
image: budry/registry-arm:v2.6.2
ports:
- 5000:5000
environment:
# The registry will be behind a reverse-proxy providing a SSL certificate
#REGISTRY_HTTP_TLS_CERTIFICATE: /deploy/registry/certs/domain.crt
#REGISTRY_HTTP_TLS_KEY: /deploy/registry/certs/domain.key
REGISTRY_AUTH: htpasswd
REGISTRY_AUTH_HTPASSWD_PATH: /auth/htpasswd
REGISTRY_AUTH_HTPASSWD_REALM: Registry Realm
volumes:
- {{ REGISTRY_DIRECTORY }}:/var/lib/registry
- /deploy/registry:/auth
[Unit]
Description=Docker registry
Requires=docker.service
After=docker.service
[Service]
Restart=always
ExecStart=/deploy/registry/restart.sh
ExecStop=/deploy/registry/stop.sh
[Install]
WantedBy=local.target
#!/bin/bash
cd /deploy/registry
docker-compose down
docker-compose up -d
sleep 15 && systemctl restart reverse_proxy
#!/bin/bash
cd /deploy/registry && docker-compose down
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment