From 661a0a46d62798b653d23915b0e08b0ec5d92ffb Mon Sep 17 00:00:00 2001 From: Avnish Pratap Singh Date: Thu, 30 May 2024 11:30:31 +0100 Subject: [PATCH] Publish docker image --- .github/workflows/publish-docker-image.yml | 64 ++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 .github/workflows/publish-docker-image.yml diff --git a/.github/workflows/publish-docker-image.yml b/.github/workflows/publish-docker-image.yml new file mode 100644 index 000000000..292248145 --- /dev/null +++ b/.github/workflows/publish-docker-image.yml @@ -0,0 +1,64 @@ +name: "Publish Docker Image" + +on: + push: + tags: + - "**" + +jobs: + build: + runs-on: ubuntu-latest + defaults: + run: + shell: bash -l -e -o pipefail {0} + + env: + IMAGE_NAME: p4 + REPOSITORY_OWNER: ${{ github.repository_owner }} + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: "Fetch Tags" + # Workaround for https://github.com/actions/checkout/issues/290 + run: git fetch --tags --force + + - name: "Get release variables" + # RELEASE_VERSION assignment must match the command used in autoconf's + # configure.ac file. On update, care should be taken to maintain both + # sides congruent. + run: | + echo 'RELEASE_VERSION='$(git describe --always --tags --dirty) >> $GITHUB_ENV + echo 'GIT_URL='$(git remote get-url origin) >> $GITHUB_ENV + echo 'GIT_COMMIT='$(git log --pretty=format:'%H' -n 1) >> $GITHUB_ENV + + - name: "Login to Docker registry" + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: "Build Docker image" + run: | + docker build --rm \ + --file Dockerfile \ + --platform linux/amd64 \ + --progress plain \ + --load \ + --label "org.opencontainers.image.title=${IMAGE_NAME}" \ + --label "org.opencontainers.image.source=${GIT_URL}" \ + --label "org.opencontainers.image.revision=${GIT_COMMIT}" \ + --label "org.opencontainers.image.version=${RELEASE_VERSION}" \ + --label "org.opencontainers.image.created=$(date --utc --iso-8601=seconds)" \ + --tag "ghcr.io/${REPOSITORY_OWNER}/${IMAGE_NAME}:${RELEASE_VERSION}" \ + --tag "ghcr.io/${REPOSITORY_OWNER}/${IMAGE_NAME}:latest" \ + . + + - name: "Push Docker image to registry" + run: | + docker push "ghcr.io/$REPOSITORY_OWNER/$IMAGE_NAME:$RELEASE_VERSION" + docker push "ghcr.io/$REPOSITORY_OWNER/$IMAGE_NAME:latest"