From cf07304baeb4ad653ed25ce8ee15e23e98877784 Mon Sep 17 00:00:00 2001 From: Kevin David Date: Sat, 27 May 2023 13:39:28 -0400 Subject: [PATCH] Allow docker username to be specified, only use one token --- .github/workflows/build.yml | 21 ++++++++++++++++++--- .github/workflows/dockerprune.yml | 6 +++--- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7271b04..06f3a7c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -195,8 +195,23 @@ jobs: uses: docker/login-action@v2 with: registry: docker.io - username: ${{ steps.string_user.outputs.lowercase }} + username: ${{ vars.DOCKER_USERNAME || steps.string_user.outputs.lowercase }} password: ${{ secrets.DOCKER_TOKEN }} + - name: Set Docker name with owner (package name) depending on if DOCKER_USERNAME is set + if: ${{ steps.vars.outputs.HAS_SECRET_TOKEN }} + id: docker_repo + shell: bash + run: | + if [ -z $DOCKER_USERNAME ]; then + echo "DOCKER_NWO=${GITHUB_NWO}" >> $GITHUB_OUTPUT + else + IFS='/' read -ra NWO_SPLIT <<< "$GITHUB_NWO" + REPO_NAME=${NWO_SPLIT[1]} + echo "DOCKER_NWO=${DOCKER_USERNAME}/${REPO_NAME}" >> $GITHUB_OUTPUT + fi + env: + DOCKER_USERNAME: ${{ vars.DOCKER_USERNAME }} + GITHUB_NWO: ${{ steps.string_repo.outputs.lowercase }} - name: Get tag name if: ${{ steps.vars.outputs.HAS_SECRET_TOKEN }} id: tags @@ -226,7 +241,7 @@ jobs: echo "TAGS=${tagstr}" echo "TAGS=${tagstr}" >> "${GITHUB_OUTPUT}" env: - REPO_NAME: ${{ steps.string_repo.outputs.lowercase }} + REPO_NAME: ${{ steps.docker_repo.outputs.DOCKER_NWO }} - name: Install latest rust run: | rustup toolchain install stable @@ -272,7 +287,7 @@ jobs: push: true file: Dockerfile tags: ${{ steps.tags.outputs.TAGS }} - build-args: VERSION=${{ steps.toml.outputs.version }}, REPO=${{ github.repository }}, OWNER=${{ github.repository_owner }} + build-args: VERSION=${{ steps.toml.outputs.version }}, REPO=${{ github.repository }}, OWNER=${{ vars.DOCKER_USERNAME || github.repository_owner }} env: DOCKER_BUILDKIT: 1 diff --git a/.github/workflows/dockerprune.yml b/.github/workflows/dockerprune.yml index d932958..3c339dd 100644 --- a/.github/workflows/dockerprune.yml +++ b/.github/workflows/dockerprune.yml @@ -31,7 +31,7 @@ jobs: if [ -n $SECRET ]; then HAS_SECRET='true' ; fi echo "HAS_SECRET_TOKEN=${HAS_SECRET}" >> $GITHUB_OUTPUT env: - SECRET: "${{ secrets.DOCKER_PRUNE_TOKEN }}" + SECRET: "${{ secrets.DOCKER_TOKEN }}" - name: Convert username to lower case for docker id: string_user if: ${{ steps.vars.outputs.HAS_SECRET_TOKEN }} @@ -143,5 +143,5 @@ jobs: env: DAYS: "100" REPO_NAME: ${{ steps.string_repo.outputs.lowercase }} - OWNER: ${{ steps.string_user.outputs.lowercase }} - TOKEN: ${{ secrets.DOCKER_PRUNE__TOKEN }} \ No newline at end of file + OWNER: ${{ vars.DOCKER_USERNAME || steps.string_user.outputs.lowercase }} + TOKEN: ${{ secrets.DOCKER_TOKEN }} \ No newline at end of file