Preview Image #2
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 | |
push: | |
tags: | |
- '*-dev' | |
jobs: | |
build-skip-check: | |
runs-on: ubuntu-22.04 | |
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 }} | |
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: actions/download-artifact@v4 | |
with: | |
name: frontend | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
run_id: ${{ github.event.workflow_run }} | |
- 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" | |
- name: Build and push preview image to Docker Hub | |
uses: docker/build-push-action@v5 | |
with: | |
push: true | |
context: . | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
platforms: ${{ matrix.platform }} | |
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true | |
build-args: | | |
FRONTEND_BUILD_MODE=1 | |
env: | |
DOCKER_CONTENT_TRUST: true | |
- name: Upload digest | |
uses: actions/upload-artifact@v4 | |
with: | |
name: digests | |
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: | |
name: digests | |
path: /tmp/digests | |
- name: Setup Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY_IMAGE }} | |
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 '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) | |
- name: Inspect image | |
run: | | |
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} | |
- name: Push image to redash/preview | |
run: | | |
docker buildx imagetools create \ | |
--tag redash/preview:${{ needs.build-docker-image.outputs.version }} \ | |
${{ env.REGISTRY_IMAGE }}:preview |