From ec59f1db712e654a2f26c0ed2e46b3da96610800 Mon Sep 17 00:00:00 2001 From: Oded Ben Ozer Date: Fri, 5 Apr 2024 12:11:10 +0200 Subject: [PATCH] Better support publishing container images from forked repos (#161) Allow setting target container registry with a repo scoped variable --- .github/workflows/docker-publish-on-comment.yml | 8 ++++++-- .github/workflows/docker-publish.yml | 8 ++++++-- README.md | 8 ++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/.github/workflows/docker-publish-on-comment.yml b/.github/workflows/docker-publish-on-comment.yml index 4763d08c..af224fc4 100644 --- a/.github/workflows/docker-publish-on-comment.yml +++ b/.github/workflows/docker-publish-on-comment.yml @@ -10,6 +10,10 @@ on: types: [created] +env: + DOCKERHUB_USERNAME: ${{ vars.DOCKERHUB_USERNAME }} + IMAGE_NAME: ${{ vars.IMAGE_NAME }} + REGISTRY: ${{ vars.REGISTRY }} jobs: build: @@ -54,10 +58,10 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - name: Log into Docker Hub registry - if: secrets.DOCKERHUB_TOKEN != '' + if: env.DOCKERHUB_USERNAME != '' uses: docker/login-action@3d58c274f17dffee475a5520cbe67f0a882c4dbb with: - username: ${{ secrets.DOCKERHUB_USERNAME }} + username: ${{ env.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} # Extract metadata (tags, labels) for Docker diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index cb3e3c72..dbf7ed92 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -15,6 +15,10 @@ on: pull_request: branches: [ "main" ] +env: + DOCKERHUB_USERNAME: ${{ vars.DOCKERHUB_USERNAME }} + IMAGE_NAME: ${{ vars.IMAGE_NAME }} + REGISTRY: ${{ vars.REGISTRY }} jobs: build: @@ -56,10 +60,10 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - name: Log into Docker Hub registry - if: github.event_name != 'pull_request' && secrets.DOCKERHUB_TOKEN != '' + if: github.event_name != 'pull_request' && env.DOCKERHUB_USERNAME != '' uses: docker/login-action@3d58c274f17dffee475a5520cbe67f0a882c4dbb with: - username: ${{ secrets.DOCKERHUB_USERNAME }} + username: ${{ env.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} # Extract metadata (tags, labels) for Docker diff --git a/README.md b/README.md index efc540d6..99d24c38 100644 --- a/README.md +++ b/README.md @@ -166,6 +166,14 @@ See [here](docs/observability.md) * Add a webhook to repo setting (don't forget the `/webhook` path in the URL). * Content type needs to be `application/json`, **currently** only PR events are needed +To publish container images from a forked repo set the `IMAGE_NAME` and `REGISTRY` GitHub Action Repository variables to use GitHub packages. +`REGISTRY` should be `ghcr.io` and `IMAGE_NAME` should match the repository slug, like so: +like so: +image + + + + ## Roadmap See the [open issues](https://github.com/wayfair-incubator/telefonistka/issues) for a list of proposed features (and known issues).