Build & Push SwaggerEditor Docker image #144
This file contains hidden or 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
| # inspired by https://securitylab.github.com/research/github-actions-preventing-pwn-requests/ | |
| name: Build & Push SwaggerEditor Docker image | |
| on: | |
| workflow_run: | |
| workflows: ["Release SwaggerEditor"] | |
| types: | |
| - completed | |
| branches: [main] | |
| jobs: | |
| build-push: | |
| if: github.event.workflow_run.conclusion == 'success' | |
| name: Build & Push SwaggerEditor Docker image | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| ref: main | |
| submodules: true | |
| - name: Use Node.js 22 | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: 22 | |
| cache: npm | |
| cache-dependency-path: package-lock.json | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Build App artifacts | |
| run: npm run build:app | |
| - name: Determine released version | |
| uses: actions/github-script@v8 | |
| with: | |
| script: | | |
| const allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| run_id: context.payload.workflow_run.id, | |
| }); | |
| const matchArtifact = allArtifacts.data.artifacts.filter((artifact) => { | |
| return artifact.name == "released-version" | |
| })[0]; | |
| const download = await github.rest.actions.downloadArtifact({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| artifact_id: matchArtifact.id, | |
| archive_format: 'zip', | |
| }); | |
| const fs = require('fs'); | |
| fs.writeFileSync('${{github.workspace}}/released-version.zip', Buffer.from(download.data)); | |
| - run: | | |
| unzip released-version.zip | |
| RELEASED_VERSION=$(cat released-version.txt) | |
| echo "RELEASED_VERSION=$RELEASED_VERSION" >> $GITHUB_ENV | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to DockerHub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_SB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_SB_PASSWORD }} | |
| - name: Build docker image and push | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| push: true | |
| platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/386,linux/ppc64le,linux/s390x | |
| provenance: false | |
| tags: swaggerapi/swagger-editor:latest,swaggerapi/swagger-editor:v${{ env.RELEASED_VERSION }} | |
| - name: Build unprivileged docker image and push | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: Dockerfile.unprivileged | |
| push: true | |
| platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/386,linux/ppc64le,linux/s390x | |
| provenance: false | |
| tags: swaggerapi/swagger-editor:latest-unprivileged,swaggerapi/swagger-editor:v${{ env.RELEASED_VERSION }}-unprivileged |