-
Notifications
You must be signed in to change notification settings - Fork 5
145 lines (131 loc) · 4.34 KB
/
docker-build.yaml
File metadata and controls
145 lines (131 loc) · 4.34 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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
name: "Docker build"
on:
workflow_call:
inputs:
docker_file:
type: string
required: true
image_name:
type: string
required: true
test_services_to_start:
type: string
test_script:
type: string
push_image:
type: boolean
host_machine_platform:
type: string
required: false
default: ubuntu-20.04
build_platforms:
type: string
required: true
secrets:
dockerhub_username:
description: 'Required if the docker image is pushed'
required: false
dockerhub_token:
required: false
jobs:
build:
runs-on: ${{ inputs.host_machine_platform }}
steps:
- uses: actions/checkout@v3.5.2
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-v1-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-v1-
- name: Setup qemu
if: contains(inputs.build_platforms, 'arm64')
uses: docker/setup-qemu-action@v2.2.0
with:
platforms: arm64
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3.3.0
with:
driver-opts: |
network=host
- uses: docker/login-action@v3.1.0
if: ${{inputs.push_image}}
with:
username: ${{ secrets.dockerhub_username }}
password: ${{ secrets.dockerhub_token }}
- name: Get current Broker git tag (for Docker meta)
run: |
git fetch --tags origin --force
echo "broker_head_tag=$(git tag --points-at HEAD --list 'broker/v*')" >> $GITHUB_ENV
- name: Docker meta
id: docker_meta_success
uses: docker/metadata-action@v5.5.1
if: ${{inputs.push_image}}
with:
images: ${{inputs.image_name}}
flavor: |
latest=false
tags: |
type=match,pattern=broker/(v.*),group=1,value=${{ env.broker_head_tag }}
type=raw,value=dev,enable=${{ github.ref == 'refs/heads/main' }}
- name: Build
if: ${{!inputs.push_image}}
uses: docker/build-push-action@v6.3.0
with:
context: .
file: ${{inputs.docker_file}}
platforms: ${{inputs.build_platforms}}
push: false
load: true
build-args: |
NODE_ENV=development
tags: ${{inputs.image_name}}:dev
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
- name: Start Streamr Docker Stack
if: ${{inputs.test_services_to_start && inputs.test_script }}
uses: streamr-dev/streamr-docker-dev-action@v1.0.1
with:
services-to-start: ${{inputs.test_services_to_start}}
- name: Run test script
if: ${{inputs.test_services_to_start && inputs.test_script }}
run: ${{inputs.test_script}}
- name: Build & Push
if: ${{inputs.push_image}}
uses: docker/build-push-action@v6.3.0
with:
context: .
file: ${{inputs.docker_file}}
platforms: ${{inputs.build_platforms}}
push: true
load: false
build-args: |
NODE_ENV=production
tags: ${{ steps.docker_meta_success.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
- name: Collect docker logs on failure
if: failure()
uses: jwalton/gh-docker-logs@v2.2.1
with:
dest: 'logs'
- name: Upload logs to GitHub
if: failure()
uses: actions/upload-artifact@v4
with:
name: docker-logs-node${{ matrix.node-version }}--${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt}}
path: 'logs'
- name: Stop Streamr Docker Stack
if: always()
run: |
docker kill $(docker ps -q)
docker rm $(docker ps -a -q)
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache