From dfe05b08ad8fd526bd7e91234836b49591287dbf Mon Sep 17 00:00:00 2001 From: Augustine Abaris Date: Thu, 5 Sep 2024 11:37:33 -0400 Subject: [PATCH] Add build config and workflow for the ansible container --- .github/workflows/container-build.yaml | 62 ++++++++++++++++++++++++++ Dockerfile | 36 +++++++++++++++ lint.sh | 3 ++ requirements.txt | 4 ++ 4 files changed, 105 insertions(+) create mode 100644 .github/workflows/container-build.yaml create mode 100644 Dockerfile create mode 100644 lint.sh create mode 100644 requirements.txt diff --git a/.github/workflows/container-build.yaml b/.github/workflows/container-build.yaml new file mode 100644 index 0000000..793fda1 --- /dev/null +++ b/.github/workflows/container-build.yaml @@ -0,0 +1,62 @@ +name: Build Container + +on: + push: + branches: [main] + # Publish semver tags as releases. + tags: ['v*.*.*'] + pull_request: + branches: [main] + +env: + # Use docker.io for Docker Hub if empty + REGISTRY: ghcr.io + # github.repository as / + IMAGE_NAME: ${{ github.repository }} + +jobs: + build: + + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + # Login against a Docker registry except on PR + # https://github.com/docker/login-action + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Extract metadata (tags, labels) for Docker + # https://github.com/docker/metadata-action + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=semver,pattern=v{{version}} + type=semver,pattern=v{{major}}.{{minor}} + type=semver,pattern=v{{major}} + type=ref,event=branch + type=ref,event=pr + type=sha + + # Build and push Docker image with Buildx (don't push on PR) + # https://github.com/docker/build-push-action + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: ./container + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..cdfb9c5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,36 @@ +# Builder Image + +FROM python:3.10-slim-bullseye as builder + +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + build-essential \ + libffi-dev && \ + apt-get clean -y + +RUN mkdir -p /srv/docker-ansible + +COPY requirements.txt /srv/docker-ansible/requirements.txt + +RUN python3 -m venv /srv/docker-ansible/env && \ + /srv/docker-ansible/env/bin/pip install -r /srv/docker-ansible/requirements.txt + +# Final Image + +FROM python:3.10-slim-bullseye + +MAINTAINER New England Research Cloud (NERC) "https://nerc.mghpcc.org" + +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + ssh \ + git \ + && apt-get clean -y + +COPY --from=builder /srv/docker-ansible /srv/docker-ansible + +COPY lint.sh /srv/docker-ansible/env/bin/lint.sh + +ENTRYPOINT [] + +CMD ["/srv/docker-ansible/env/bin/ansible-playbook"] diff --git a/lint.sh b/lint.sh new file mode 100644 index 0000000..f7a7256 --- /dev/null +++ b/lint.sh @@ -0,0 +1,3 @@ +#!/bin/bash +set -e +/srv/docker-ansible/env/bin/ansible-lint --exclude ${HOME}/.ansible/roles/ $@ diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..f094db5 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +ansible==8.2.0 +ansible-lint==6.17.2 +dnspython==2.4.2 +omsdk==1.2.509