Pack ansible in docker
This module is to write Dockerfile, push to Gitlab, write Gitlab CI job to build a container from the Dockerfile & upload to Gitlab Container registry.
Step 1: Dockerfile (do not use - because of issues with Ansible collection backend)
FROM alpine:latest
RUN apk add py3-pip \
build-base \
python3-dev \
libssh-dev \
ansible \
openssh-client
RUN pip install ansible-pylibssh
RUN apk --no-cache add ca-certificates \
&& update-ca-certificates
RUN ansible-galaxy collection install vyos.vyos
ADD ansible.cfg /etc/ansible/ansible.cfg
Step 2: Push Dockerfile on Gitlab
Step 3: Write .gitlab-ci.yml for Docker building
stages:
- Docker build
Build Container:
image: docker:latest
stage: Docker build
services:
- docker:dind
variables:
DOCKER_HOST: tcp://docker:2375/
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
script:
- docker build --pull -t "$CI_REGISTRY_IMAGE:latest" .
- docker push "$CI_REGISTRY_IMAGE:latest"
when: manual
Step4: Trigger job & ensure the container is built