-
Notifications
You must be signed in to change notification settings - Fork 44
142 lines (126 loc) · 4.73 KB
/
docker.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
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
name: Build Docker image
on:
workflow_call:
inputs:
uploadImageAsTarball:
description: 'uploads the Docker image additionally as a tarball'
required: false
default: false
type: boolean
platforms:
description: 'platforms for docker build step'
required: false
default: ''
type: string
debug:
description: 'include debug symbols in built image'
required: false
default: false
type: boolean
uploadToDockerHub:
description: 'upload image to DockerHub'
required: false
default: false
type: boolean
workflow_dispatch:
inputs:
debug:
description: 'include debug symbols in built image'
required: false
default: false
type: boolean
uploadToDockerHub:
description: 'upload image to DockerHub'
required: false
default: false
type: boolean
env:
GHCR_REGISTRY: 'ghcr.io'
REPOSITORY_OWNER: ${{ github.repository_owner }}
GHCR_REGISTRY_USERNAME: ${{ github.actor }}
GHCR_REGISTRY_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
build-and-push-image:
runs-on: ubuntu-latest
timeout-minutes: ${{ inputs.debug && 140 || 70 }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
# Setup caching
- name: Set up QEMU dependency
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.GHCR_REGISTRY }}
username: ${{ env.GHCR_REGISTRY_USERNAME }}
password: ${{ env.GHCR_REGISTRY_TOKEN }}
- name: Extract image name
# Set repository name as image name
run: |
echo "IMAGE_NAME=${GITHUB_REPOSITORY#$GITHUB_REPOSITORY_OWNER/}" >> $GITHUB_ENV
- name: Print image names
run: |
echo ${{ inputs.uploadToDockerHub && format('restatedev/{0}', env.IMAGE_NAME) || '' }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: |
${{ env.GHCR_REGISTRY }}/${{ env.REPOSITORY_OWNER }}/${{ env.IMAGE_NAME }}
${{ inputs.uploadToDockerHub && format('{0}/{1}', env.REPOSITORY_OWNER, env.IMAGE_NAME) || '' }}
# Note: We need this to generate the latest tag until we have a first stable release.
# Check https://github.com/docker/metadata-action/issues/34
flavor: |
latest=true
${{ inputs.debug && 'prefix=debug-,onlatest=true' || '' }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
- name: Build${{inputs.uploadImageAsTarball != true && ' and push ' || ' '}}Docker image
id: build
uses: docker/build-push-action@v3
with:
context: .
file: "docker/Dockerfile"
push: ${{ inputs.uploadImageAsTarball != true }}
tags: ${{ steps.meta.outputs.tags }}
load: ${{ inputs.uploadImageAsTarball == true }}
labels: ${{ steps.meta.outputs.labels }}
platforms: ${{ inputs.platforms || 'linux/arm64,linux/amd64' }}
build-args: |
CARGO_PROFILE_RELEASE_DEBUG=${{ inputs.debug }}
cache-from: type=gha,scope=${{ github.workflow }}
cache-to: type=gha,mode=max,scope=${{ github.workflow }}
- name: Save docker image as tar
if: ${{ inputs.uploadImageAsTarball }}
run: |
docker save -o restate.tar ${{ steps.build.outputs.imageid }}
- name: Upload docker image tar as artifact
if: ${{ inputs.uploadImageAsTarball }}
uses: actions/upload-artifact@v3
with:
name: restate.tar
path: restate.tar
retention-days: 1
if-no-files-found: error
# Even if uploadImageAsTarball, push main images
# This won't actually build again, it'll just use cache
- name: Push Docker image
if: ${{ inputs.uploadImageAsTarball && github.ref == 'refs/heads/main' }}
uses: docker/build-push-action@v3
with:
context: .
file: "docker/Dockerfile"
push: true
tags: ${{ steps.meta.outputs.tags }}
load: false
labels: ${{ steps.meta.outputs.labels }}
# ignore inputs.platforms as we always need to push both arm64 and amd64 docker images
platforms: 'linux/arm64,linux/amd64'
build-args: |
CARGO_PROFILE_RELEASE_DEBUG=${{ inputs.debug }}
cache-from: type=gha,scope=${{ github.workflow }}
cache-to: type=gha,mode=max,scope=${{ github.workflow }}