-
Notifications
You must be signed in to change notification settings - Fork 4.4k
154 lines (150 loc) · 5.46 KB
/
preview-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
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
146
147
148
149
150
151
152
153
154
name: Preview Image
on:
workflow_run:
workflows:
- Tests
types:
- completed
branches:
- master
env:
DOCKER_REPO: redash
jobs:
build-skip-check:
runs-on: ubuntu-22.04
if: ${{ github.event.workflow_run.conclusion == 'success' }}
outputs:
skip: ${{ steps.skip-check.outputs.skip }}
steps:
- name: Skip?
id: skip-check
run: |
if [[ "${{ vars.DOCKER_USER }}" == '' ]]; then
echo 'Docker user is empty. Skipping build+push'
echo skip=true >> "$GITHUB_OUTPUT"
elif [[ "${{ secrets.DOCKER_PASS }}" == '' ]]; then
echo 'Docker password is empty. Skipping build+push'
echo skip=true >> "$GITHUB_OUTPUT"
else
echo 'Docker user and password are set and branch is `master`.'
echo 'Building + pushing `preview` image.'
echo skip=false >> "$GITHUB_OUTPUT"
fi
build-docker-image:
runs-on: ubuntu-22.04
needs:
- build-skip-check
outputs:
version: ${{ steps.version.outputs.VERSION_TAG }}
repo: ${{ steps.version.outputs.DOCKER_REPO }}
if: needs.build-skip-check.outputs.skip == 'false'
strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
- linux/arm64
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
ref: ${{ github.event.push.after }}
- uses: dawidd6/action-download-artifact@v3
with:
name: frontend
workflow: ci.yml
github_token: ${{ secrets.GITHUB_TOKEN }}
run_id: ${{ github.event.workflow_run.id }}
path: client/dist
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASS }}
- name: Set version
id: version
run: |
set -x
VERSION=$(jq -r .version package.json)
FULL_VERSION=${VERSION}-b${GITHUB_RUN_ID}.${GITHUB_RUN_NUMBER}
sed -ri "s/^__version__ = ([A-Za-z0-9.-]*)'/__version__ = '${FULL_VERSION}'/" redash/__init__.py
sed -i "s/dev/${GITHUB_SHA}/" client/app/version.json
echo "VERSION_TAG=$FULL_VERSION" >> "$GITHUB_OUTPUT"
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
echo "SCOPE=${platform//\//-}" >> $GITHUB_ENV
if [[ "${{ vars.DOCKER_REPO }}" != "" ]]; then
echo "DOCKER_REPO=${{ vars.DOCKER_REPO }}" >> $GITHUB_ENV
echo "DOCKER_REPO=${{ vars.DOCKER_REPO }}" >> $GITHUB_OUTPUT
else
echo "DOCKER_REPO=${DOCKER_REPO}" >> $GITHUB_ENV
echo "DOCKER_REPO=${DOCKER_REPO}" >> $GITHUB_OUTPUT
fi
- name: Build and push preview image to Docker Hub
uses: docker/build-push-action@v5
id: build
with:
push: true
context: .
cache-from: type=gha,scope=${{ env.SCOPE }}
cache-to: type=gha,mode=max,scope=${{ env.SCOPE }}
platforms: ${{ matrix.platform }}
outputs: type=image,name=${{ env.DOCKER_REPO }}/redash,push-by-digest=true,name-canonical=true,push=true
build-args: |
FRONTEND_BUILD_MODE=1
env:
DOCKER_CONTENT_TRUST: true
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ env.PLATFORM_PAIR }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
publish-docker-manifest:
runs-on: ubuntu-22.04
needs:
- build-skip-check
- build-docker-image
if: needs.build-skip-check.outputs.skip == 'false'
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
pattern: digests-*
path: /tmp/digests
merge-multiple: true
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ needs.build-docker-image.outputs.repo }}/redash
tags: preview
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASS }}
- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ needs.build-docker-image.outputs.repo }}/redash@sha256:%s ' *)
- name: Inspect image
run: |
REDASH_IMAGE="${{ needs.build-docker-image.outputs.repo }}/redash:${{ steps.meta.outputs.version }}"
docker buildx imagetools inspect $REDASH_IMAGE
- name: Push image ${{ needs.build-docker-image.outputs.repo }}/preview image
run: |
REDASH_IMAGE="${{ needs.build-docker-image.outputs.repo }}/redash:preview"
PREVIEW_IMAGE="${{ needs.build-docker-image.outputs.repo }}/preview:${{ needs.build-docker-image.outputs.version }}"
docker buildx imagetools create --tag $PREVIEW_IMAGE $REDASH_IMAGE