-
Notifications
You must be signed in to change notification settings - Fork 53
83 lines (81 loc) · 2.93 KB
/
build_and_push_image.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
---
name: Build and push narrative images
on:
workflow_call:
secrets:
GHCR_USERNAME:
required: true
GHCR_TOKEN:
required: true
jobs:
docker_build_image:
if: github.event.pull_request.draft == false
runs-on: ubuntu-latest
steps:
-
name: Check out GitHub Repo
with:
ref: "${{ github.event.pull_request.head.sha }}"
uses: actions/checkout@main
-
name: Set up environment
run: |
if [ ${{ github.base_ref }} == 'main' ]; then
branch=''
else
branch=`echo "-""${{ github.base_ref }}" | awk '{print tolower($0)}'`
fi
narrative_version=`grep '\"version\":' src/config.json.templ | awk '{print $2}' | sed 's/"//g'`
narrative_git_hash=`grep '\"git_commit_hash\":' src/config.json.templ | awk '{print $2}' | sed 's/"//g' | sed 's/,//'`
echo "APP_IMAGE_TAG=ghcr.io/${{ github.repository }}${branch}:pr-${{ github.event.pull_request.number }}" >> $GITHUB_ENV
echo "APP_VERSION_IMAGE_TAG=ghcr.io/${{ github.repository }}${branch}_version:pr-${{ github.event.pull_request.number }}" >> $GITHUB_ENV
echo "BRANCH=${branch}" >> $GITHUB_ENV
echo "NARRATIVE_GIT_HASH=${narrative_git_hash}" >> $GITHUB_ENV
echo "NARRATIVE_VERSION=${narrative_version}" >> $GITHUB_ENV
echo "PR=pr-${{ github.event.pull_request.number }}" >> $GITHUB_ENV
echo "VCS_REF=$(echo "${{ github.event.pull_request.head.sha }}" | cut -c -7)" >> $GITHUB_ENV
-
name: Get current date
id: date
run: echo "date=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@master
-
name: Log in to the Container registry
uses: docker/login-action@master
with:
registry: ghcr.io
username: ${{ secrets.GHCR_USERNAME }}
password: ${{ secrets.GHCR_TOKEN }}
-
name: Build narrative image
uses: docker/build-push-action@master
with:
context: .
file: ./Dockerfile
pull: true
push: true
tags: ${{ env.APP_IMAGE_TAG }}
build-args: |
BRANCH=${{ github.head_ref }}
BUILD_DATE=${{ steps.date.output.date }}
NARRATIVE_VERSION=${{ env.NARRATIVE_VERSION }}
VCS_REF=${{ github.sha }}
TAG='${{ github.ref }}'
-
name: Build version image
uses: docker/build-push-action@master
if: ${{ github.base_ref }} == 'main' || ${{ github.base_ref }} == 'develop'
with:
context: .
push: true
file: Dockerfile2
tags: ${{ env.APP_VERSION_IMAGE_TAG }}
build-args: |
BRANCH=${{ github.head_ref }}
BUILD_DATE=${{ steps.date.output.date }}
NARRATIVE_VERSION=${{ env.NARRATIVE_VERSION }}
NARRATIVE_GIT_HASH=${{ env.NARRATIVE_GIT_HASH }}
VCS_REF=${{ github.sha }}
TAG='${{ github.ref }}'