-
Notifications
You must be signed in to change notification settings - Fork 1
51 lines (43 loc) · 1.56 KB
/
docker-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
name: Bantool CI/CD
on:
push:
branches:
- 'master'
- 'id-swap'
env:
IMAGE: 'strudelboogie'
REGISTRY_HOSTNAME: 'gcr.io'
PROJECT_ID: '${{ secrets.GCP_PROJECT_ID }}'
jobs:
build:
name: 'build and push'
runs-on: 'ubuntu-latest'
steps:
- uses: 'actions/checkout@v3'
- name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v1'
with:
credentials_json: '${{ secrets.GCR_KEY }}'
- name: 'Set up Google Cloud SDK'
uses: 'google-github-actions/[email protected]'
with:
project_id: '${{ env.PROJECT_ID }}'
service_account_key: '${{ secrets.GCR_KEY }}'
- name: 'Configure Docker to use gcloud command-line tool'
run: 'gcloud auth configure-docker'
- name: 'Set Image Tag'
id: set_tag
run: |
if [[ ${{ github.ref }} == 'refs/heads/master' ]]; then
echo "TAG=latest" >> $GITHUB_ENV
else
echo "TAG=testing" >> $GITHUB_ENV
fi
- name: 'build/push image'
run: |
docker build -t $REGISTRY_HOSTNAME/$PROJECT_ID/$IMAGE:${{ env.TAG }} -f Dockerfile .
docker push $REGISTRY_HOSTNAME/$PROJECT_ID/$IMAGE:${{ env.TAG }}
if [[ ${{ env.TAG }} == 'latest' ]]; then
docker tag $REGISTRY_HOSTNAME/$PROJECT_ID/$IMAGE:latest $REGISTRY_HOSTNAME/$PROJECT_ID/$IMAGE:$GITHUB_SHA
docker push $REGISTRY_HOSTNAME/$PROJECT_ID/$IMAGE:$GITHUB_SHA
fi