From 9e954c83afd3addc44bdd0fe9dca00ec129e1ec3 Mon Sep 17 00:00:00 2001 From: George Taylor Date: Tue, 13 Aug 2024 23:19:22 +0100 Subject: [PATCH] :recycle: Add image build (#66) --- .github/workflows/image-build.yml | 58 +++++++++++++++++++++++++++++++ Dockerfile | 12 +++++++ 2 files changed, 70 insertions(+) create mode 100644 .github/workflows/image-build.yml create mode 100644 Dockerfile diff --git a/.github/workflows/image-build.yml b/.github/workflows/image-build.yml new file mode 100644 index 0000000..b40917f --- /dev/null +++ b/.github/workflows/image-build.yml @@ -0,0 +1,58 @@ +name: "Image Build" + +on: + workflow_dispatch: + push: + tags: + - 'v*' + +run-name: "Image Build for tag ${{ github.ref_name }}" + +permissions: + packages: write + contents: write + +jobs: + build-and-push: + runs-on: ubuntu-22.04 + + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Create safe tag for image + id: safe_tag + run: | + echo "SAFE_TAG=$(echo ${{ github.ref_name }} | sed 's/[^a-zA-Z0-9.]/-/g')" >> $GITHUB_OUTPUT + + - name: Set up Docker Buildx + id: setup_buildx + uses: docker/setup-buildx-action@v3 + + - name: Log into ghcr + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push to ghcr + id: build_publish + uses: docker/build-push-action@v6 + with: + context: . + platforms: linux/amd64, linux/arm64 + push: true + tags: ghcr.io/ministryofjustice/hmpps-ldap-automation:${{ steps.safe_tag.outputs.SAFE_TAG }} + build-args: | + VERSION_REF=${{ steps.BumpVersionAndPushTag.outputs.new_tag }} + + - name: Slack failure notification + if: ${{ failure() }} + uses: slackapi/slack-github-action@70cd7be8e40a46e8b0eced40b0de447bdb42f68e # v1.26.0 + with: + payload: | + {"blocks":[{"type": "section","text": {"type": "mrkdwn","text": ":no_entry: Failed GitHub Action:"}},{"type": "section","fields":[{"type": "mrkdwn","text": "*Workflow:*\n<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|${{ github.workflow }}>"},{"type": "mrkdwn","text": "*Job:*\n${{ github.job }}"},{"type": "mrkdwn","text": "*Repo:*\n${{ github.repository }}"}]}]} + env: + SLACK_WEBHOOK_URL: ${{ secrets.PWO_PUBLIC_SLACK_WEBHOOK_URL }} + SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3afcbe8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM python:3.10-alpine + +LABEL org.opencontainers.image.source = "https://github.com/ministryofjustice/hmpps-ldap-automation-cli" + +ARG VERSION_REF=main + +# Basic tools for now +RUN apk add --update --no-cache bash ca-certificates git build-base libffi-dev openssl-dev gcc musl-dev gcc g++ linux-headers build-base openldap-dev python3-dev + +RUN python3 -m pip install --upgrade pip && python3 -m pip install git+https://github.com/ministryofjustice/hmpps-ldap-automation-cli.git@${VERSION_REF} + +CMD ["ldap-automation"]