-
Notifications
You must be signed in to change notification settings - Fork 8
113 lines (97 loc) · 3.5 KB
/
build_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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
name: Build App component image
on:
release:
types: [ published ]
workflow_dispatch:
inputs:
tag:
description: Image tag
required: true
jobs:
build:
runs-on: ubuntu-latest
# see https://github.com/docker/build-push-action
steps:
# Setup (see https://github.com/docker/build-push-action)
- name: Checkout
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# Publish to Docker hub
- name: Store version number (on release)
if: ${{ github.event_name == 'release' }}
id: version
# GITHUB_REF looks like "refs/tags/0.3.1" - we need to extract the actual version without the v prefix
run: echo "number=${GITHUB_REF##*/}" >> $GITHUB_OUTPUT
# Caches
- name: Cache var-cache-apt
id: cache-var-cache-apt
uses: actions/cache@v3
with:
path: var-cache-apt
key: var-cache-apt-${{ hashFiles('Dockerfile') }}
- name: Cache var-lib-apt
id: cache-var-lib-apt
uses: actions/cache@v3
with:
path: var-lib-apt
key: var-lib-apt-${{ hashFiles('Dockerfile') }}
- name: Cache root-.cache
id: cache-root-cache
uses: actions/cache@v3
with:
path: root-.cache
key: root-.cache-${{ hashFiles('Dockerfile') }}
- name: inject var-cache-apt into docker
uses: reproducible-containers/[email protected]
with:
cache-source: var-cache-apt
cache-target: /var/cache/apt
skip-extraction: ${{ steps.cache-var-cache-apt.outputs.cache-hit }}
- name: inject var-lib-apt into docker
uses: reproducible-containers/[email protected]
with:
cache-source: var-lib-apt
cache-target: /var/lib/apt
skip-extraction: ${{ steps.cache-var-lib-apt.outputs.cache-hit }}
- name: inject root-.cache into docker
uses: reproducible-containers/[email protected]
with:
cache-source: root-.cache
cache-target: /root/.cache
skip-extraction: ${{ steps.cache-root-cache.outputs.cache-hit }}
# Release push (with a tag)
- name: Build and push (on release)
if: ${{ github.event_name == 'release' }}
uses: docker/build-push-action@v4
with:
push: true
context: .
target: app
file: Dockerfile
cache-from: type=registry,ref=blsq/openhexa-app:buildcache
cache-to: type=registry,ref=blsq/openhexa-app:buildcache,mode=max
tags: |
blsq/openhexa-app:${{ steps.version.outputs.number }}
blsq/openhexa-app:latest
# Manual push
- name: Build and push (manual)
if: ${{ github.event_name == 'workflow_dispatch' }}
uses: docker/build-push-action@v4
with:
push: true
context: .
target: app
file: Dockerfile
cache-from: type=registry,ref=blsq/openhexa-app:buildcache
cache-to: type=registry,ref=blsq/openhexa-app:buildcache,mode=max
tags: |
blsq/openhexa-app:${{ github.event.inputs.tag }}
blsq/openhexa-app:latest