Skip to content

Commit

Permalink
workflow: switch to variable for DockerHub username (#2)
Browse files Browse the repository at this point in the history
* workflow: sitch to variable for DockerHub username

* workflow: get DockerHub username from vars context

* workflow: remove "docker-" from DOCKERHUB_IMAGE_NAME

* workflow: fix env.DOCKERHUB_IMAGE_NAME assignment
  • Loading branch information
bwbohl authored Feb 26, 2025
1 parent 431f420 commit eb08939
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,25 @@ env:
IMAGE_NAME: ${{ github.repository }}
# github repository name as <repo>
# might even be set through echo "$GITHUB_REPOSITORY" | awk -F / '{print $2}' | sed -e "s/:refs//" if usernames on GitHub and DockerHub are identical
DOCKERHUB_IMAGE_NAME: ""
# DOCKERHUB_IMAGE_NAME: ${{ null }}
# boolean whether to push or not
PUSH: false




jobs:
#init:
# runs-on: ubuntu-latest
# permissions:
# contents: read
# packages: write
# # This is used to complete the identity challenge
# # with sigstore/fulcio when running outside of PRs.
# id-token: write
# steps:


build:

runs-on: ubuntu-latest
Expand All @@ -41,6 +52,18 @@ jobs:
id-token: write

steps:

# Set DOCKERHUB_IMAGE_NAME
- name: Set DOCKERHUB_IMAGE_NAME
if: github.repository_owner == ${{ vars.DOCKERHUB_USERNAME }}
run: echo DOCKERHUB_IMAGE_NAME=$(echo "$GITHUB_REPOSITORY" | awk -F / '{print $2}' | sed -e 's/docker-//') >> $GITHUB_ENV

- name: Echo DOCKERHUB_IMAGE_NAME
run: echo "$env.DOCKERHUB_IMAGE_NAME"

- name: Echo variables
run: env

- name: Checkout repository
uses: actions/checkout@v4

Expand Down Expand Up @@ -74,14 +97,9 @@ jobs:
if: github.event_name != 'pull_request'
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

# Set DOCKERHUB_IMAGE_NAME
- name: Set DOCKERHUB_IMAGE_NAME
if: github.repository_owner == ${{ secrets.DOCKERHUB_USERNAME }}
run: echo "DOCKERHUB_IMAGE_NAME=$GITHUB_REPOSITORY" | awk -F / '{print $2}' | sed -e "s/:refs//" >> $GITHUB_ENV

# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
Expand All @@ -90,7 +108,7 @@ jobs:
with:
images: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.DOCKERHUB_IMAGE_NAME }}
${{ vars.DOCKERHUB_USERNAME }}/${{ env.DOCKERHUB_IMAGE_NAME }}
flavor: |
latest=${{ github.ref == 'refs/heads/main' }}
Expand Down

0 comments on commit eb08939

Please sign in to comment.