Preview Image #46
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |