-
Notifications
You must be signed in to change notification settings - Fork 0
67 lines (58 loc) · 2.06 KB
/
docker-build-push.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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: 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 }}