-
Notifications
You must be signed in to change notification settings - Fork 0
77 lines (69 loc) · 2.23 KB
/
Copy pathdocker-build.yml
File metadata and controls
77 lines (69 loc) · 2.23 KB
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
name: Build & Push Docker
on:
push:
branches:
- "**"
tags-ignore:
- '**'
paths:
- 'init-db.sh'
- 'Dockerfile'
- '.github/workflows/docker-build.yml'
workflow_dispatch:
env:
NAMESPACE: ${{ secrets.docker_hub_organisation || 'openg2p' }}
REGISTRY: docker.io
jobs:
build-postgres-init:
name: Build Postgres Init Docker Image
runs-on: ubuntu-latest
env:
SERVICE_NAME: postgres-init
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Extract branch name
shell: bash
run: |
BRANCH_NAME=$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')
VERSION=$BRANCH_NAME
if [[ $BRANCH_NAME == master || $BRANCH_NAME == main ]]; then
VERSION=develop
fi
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "IMAGE_ID=${{ env.NAMESPACE }}/${{ env.SERVICE_NAME }}" >> $GITHUB_ENV
- name: Build Docker image
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
push: false
tags: ${{ env.IMAGE_ID }}:${{ env.VERSION }}
build-args: |
GIT_COMMIT=${{ github.sha }}
BUILD_TIME=${{ github.event.head_commit.timestamp }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Login to Docker Hub
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
uses: docker/login-action@v3
with:
username: ${{ secrets.docker_hub_actor }}
password: ${{ secrets.docker_hub_token }}
- name: Push Docker image
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
push: true
tags: ${{ env.IMAGE_ID }}:${{ env.VERSION }}
build-args: |
GIT_COMMIT=${{ github.sha }}
BUILD_TIME=${{ github.event.head_commit.timestamp }}
cache-from: type=gha
cache-to: type=gha,mode=max