Skip to content

Merge pull request #61 from vzdc-artcc/next #19

Merge pull request #61 from vzdc-artcc/next

Merge pull request #61 from vzdc-artcc/next #19

name: Build and Push Docker Image
on:
push:
branches:
- master
- next
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch
- name: Extract commit hash
id: commit_hash
run: |
COMMIT_HASH=${GITHUB_SHA::7} # Get the first 7 characters of the commit hash
echo "COMMIT_HASH=${COMMIT_HASH,,}" >> $GITHUB_ENV # Convert to lowercase
- name: Check for localhost in NEXT_PUBLIC_ variables
run: |
for var in $(printenv | grep '^NEXT_PUBLIC_' | cut -d= -f1); do
value=$(printenv $var)
if [[ "$value" == *"localhost"* ]]; then
echo "ERROR: $var contains 'localhost'. This is not allowed."
exit 1
fi
done
- name: Login to GCR
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set version number
run: |
if [ -f "package.json" ]; then
VERSION=v$(node -p "require('./package.json').version")-${{ steps.extract_branch.outputs.branch }}.${{ env.COMMIT_HASH }}
echo "VERSION=${VERSION}" >> $GITHUB_ENV
npm version "${VERSION}" --no-git-tag-version --allow-same-version
else
echo "package.json not found!"
exit 1
fi
- name: Rename .env.public to .env
run: mv .env.public .env
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
push: true
tags: |
ghcr.io/${{ github.repository }}:${{ steps.extract_branch.outputs.branch }}-latest
ghcr.io/${{ github.repository }}:${{ steps.extract_branch.outputs.branch }}-${{ env.COMMIT_HASH }}