From 91cfa33ffc4e48b1edfc2eaf9eaa4af91ada8481 Mon Sep 17 00:00:00 2001 From: Dan Grebb Date: Tue, 20 Feb 2024 21:33:43 -0500 Subject: [PATCH] refactor: move dockerhub build and push to separate workflow --- .github/workflows/docker-build.yml | 7 +-- .github/workflows/dockerhub-build-push.yml | 58 ++++++++++++++++++++++ 2 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/dockerhub-build-push.yml diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 2c8975964..bcdb351fb 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -40,8 +40,9 @@ jobs: - name: Log in to the Container registry uses: docker/login-action@v3 with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - name: ⬢ Setup Node & Cache uses: actions/setup-node@v4 @@ -58,7 +59,7 @@ jobs: - name: 🐳 Build & Push Docker run: | - docker buildx build --push --platform linux/amd64,linux/arm64 -t dgrebb/downstream_backstopjs:$TAG --build-arg BACKSTOPJS_VERSION=$PV docker + docker buildx build --push --platform linux/amd64,linux/arm64 -t $REGISTRY/$IMAGE_NAME_LC:$TAG --build-arg BACKSTOPJS_VERSION=$PV docker # - name: 🐳 Load Docker # run: | diff --git a/.github/workflows/dockerhub-build-push.yml b/.github/workflows/dockerhub-build-push.yml new file mode 100644 index 000000000..cb2c0f4e3 --- /dev/null +++ b/.github/workflows/dockerhub-build-push.yml @@ -0,0 +1,58 @@ +name: Docker Hub Build & Push + +on: + workflow_dispatch: + workflow_call: + +permissions: + actions: write + checks: write + contents: write + pull-requests: write + packages: write + +env: + BRANCH_NAME: ${{ github.event.pull_request.head_ref || github.event.pull_request.head.ref_name || github.head_ref || github.ref_name }} + NODE_VERSION: 20 + +jobs: + build-and-push-image: + name: 🐳 Build and Push + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 1 + ref: ${{ github.event.pull_request.head.sha || github.ref }} + + - name: Set Name and Tag Vars + env: + name: "${{ env.BRANCH_NAME }}" + run: | + echo "TAG=${name/\//-}" >> $GITHUB_ENV + echo "PV=$(cat package.json | jq -r '.version')" >> $GITHUB_ENV + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: ⬢ Setup Node & Cache + uses: actions/setup-node@v4 + with: + cache: "npm" + cache-dependency-path: package-lock.json + + - name: ↧ Install + run: npm ci --verbose --foreground-scripts + + - name: 🐳 Build Docker Builder + run: | + npm run --verbose --foreground-scripts init-docker-builder + + - name: 🐳 Build & Push Docker + run: | + docker buildx build --push --platform linux/amd64,linux/arm64 -t dgrebb/downstream_backstopjs:$TAG --build-arg BACKSTOPJS_VERSION=$PV docker