Skip to content

Commit

Permalink
ci(docker): updated docker workflow to simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
arhamj committed Oct 24, 2024
1 parent 269934e commit 03e59ff
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
27 changes: 17 additions & 10 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ name: Create and publish a Docker image
on:
push:
branches: ['dev']
pull_request:
branches: ['dev']

env:
REGISTRY: ghcr.io
Expand All @@ -31,21 +29,30 @@ jobs:
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.PAT_TOKEN }} # ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get short commit hash and determine branch name
id: set-env-vars
run: |
# Get short commit hash
echo "SHORT_COMMIT_HASH=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
# Determine branch name
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "BRANCH_NAME=${{ github.head_ref }}" >> $GITHUB_ENV # Source branch of the PR
else
echo "BRANCH_NAME=${{ github.ref_name }}" >> $GITHUB_ENV # Actual branch name for push events
fi
- name: Build and push Docker image
id: push
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.BRANCH_NAME }}-${{ env.SHORT_COMMIT_HASH }}
labels: |
version=${{ env.SHORT_COMMIT_HASH }}
branch=${{ env.BRANCH_NAME }}
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
Expand Down
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# syntax=docker/dockerfile:1

## global args
ARG NODE_VERSION=18.16.1
ARG NODE_ENV=production

FROM node:${NODE_VERSION}
SHELL [ "/bin/bash", "-cex" ]
FROM node:18.16.1-alpine
SHELL [ "/bin/sh", "-cex" ]

## ENVs
ENV NODE_ENV=${NODE_ENV}
Expand Down

0 comments on commit 03e59ff

Please sign in to comment.