Skip to content

Commit

Permalink
refactor: move dockerhub build and push to separate workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
dgrebb committed Feb 21, 2024
1 parent 2fb80ae commit 91cfa33
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: |
Expand Down
58 changes: 58 additions & 0 deletions .github/workflows/dockerhub-build-push.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 91cfa33

Please sign in to comment.