Skip to content

Build Images

Build Images #3259

Workflow file for this run

name: Build Images
on:
workflow_dispatch:
jobs:
docker:
environment: Docker build
strategy:
fail-fast: false
matrix:
branch:
- STABLE
runs-on: [ubuntu-latest]
steps:
-
name: Checkout
uses: actions/[email protected]
- name: Get run meta
id: get-run-meta
run: |
echo "vars - Branch: ${{ vars.UPSTREAM_REPO }} Branch: ${{vars[matrix.branch]}} WF: ${{ vars.UPSTREAM_WF }}"
RESPONSE=`gh run --repo ${{ vars.UPSTREAM_REPO }} list --branch ${{vars[matrix.branch]}} --workflow "${{ vars.UPSTREAM_WF }}" --json headBranch,headSha,databaseId,conclusion --jq '[.[0].databaseId, .[0].headSha, .[0].headBranch, .[0].conclusion] | @tsv' --limit 1`
echo "RESPONSE: $RESPONSE"
echo run_id=$(echo $RESPONSE | cut -f1 -d' ') >> $GITHUB_OUTPUT
echo head_sha=$(echo $RESPONSE | cut -f2 -d' ') >> $GITHUB_OUTPUT
echo branch=$(echo $RESPONSE | cut -f3 -d' ') >> $GITHUB_OUTPUT
echo success=$(echo $RESPONSE | cut -f4 -d' ') >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-
if: steps.get-run-meta.outputs.success == 'success'
name: Set Gist File Name
run: |
echo "GIST_NAME=${{vars[matrix.branch]}}.txt" >> "$GITHUB_ENV"
-
if: steps.get-run-meta.outputs.success == 'success'
name: Read Gist
uses: sergeysova/[email protected]
id: gist-read
with:
gist_id: ${{ vars[env.GIST_KEY] }}
file_name: ${{ env.GIST_NAME }}
env:
GIST_KEY: GIST_${{matrix.branch}}
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
-
if: steps.get-run-meta.outputs.success == 'success'
name: Check if build is needed
id: check-build
run: |
echo build_needed=${{ steps.gist-read.outputs.content != steps.get-run-meta.outputs.head_sha }} >> $GITHUB_OUTPUT
-
if: steps.get-run-meta.outputs.success == 'success' && steps.check-build.outputs.build_needed == 'true'
run: |
mkdir -p ./extras
- name: Download application.yml
if: steps.check-build.outputs.build_needed == 'true'
run: |
curl -o ./extras/application-ignore.yml ${{ vars.APPLICATION_YAML }}
-
name: "Download Latest Lavalink.jar"
if: steps.get-run-meta.outputs.success == 'success' && steps.check-build.outputs.build_needed == 'true'
run: |
gh run --repo "${{ vars.UPSTREAM_REPO }}" download ${{steps.get-run-meta.outputs.run_id}} -n "${{ vars.UPSTREAM_ARTIFACT }}" --dir ./extras
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
if: steps.get-run-meta.outputs.success == 'success' && steps.check-build.outputs.build_needed == 'true'
id: meta
uses: docker/[email protected]
with:
# list of Docker images to use as base name for tags
images: |
drapersniper/node
ghcr.io/pylav/node
# generate Docker tags based on the following events/attributes
tags: |
type=raw,enable=true,priority=1000,prefix=${{steps.get-run-meta.outputs.branch}}-,value=latest
type=raw,enable=true,priority=900,prefix=,suffix=,value=${{steps.get-run-meta.outputs.branch}}
type=raw,enable=true,priority=100,prefix=sha-,suffix=,value=${{steps.get-run-meta.outputs.head_sha}}
type=raw,value=latest,enable=${{ steps.get-run-meta.outputs.branch == vars.STABLE }}
-
name: Set up QEMU
if: steps.get-run-meta.outputs.success == 'success' && steps.check-build.outputs.build_needed == 'true'
uses: docker/[email protected]
-
name: Set up Docker Buildx
if: steps.get-run-meta.outputs.success == 'success' && steps.check-build.outputs.build_needed == 'true'
uses: docker/[email protected]
-
name: Login to Docker Hub
if: github.event_name != 'pull_request' && steps.get-run-meta.outputs.success == 'success' && steps.check-build.outputs.build_needed == 'true'
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Login to GHCR
if: github.event_name != 'pull_request' && steps.get-run-meta.outputs.success == 'success' && steps.check-build.outputs.build_needed == 'true'
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Build and push
if: steps.get-run-meta.outputs.success == 'success' && steps.check-build.outputs.build_needed == 'true'
uses: docker/[email protected]
with:
context: .
platforms: |
linux/amd64
linux/arm/v7
linux/arm64/v8
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha,scope=${{ env.GIST_NAME }}
cache-to: type=gha,mode=max,scope=${{ env.GIST_NAME }}
- name: Update Gist
if: steps.check-build.outputs.build_needed == 'true'
uses: sergeysova/[email protected]
with:
gist_id: ${{ vars[env.GIST_KEY] }}
file_name: ${{ env.GIST_NAME }}
content: ${{steps.get-run-meta.outputs.head_sha}}
env:
GIST_KEY: GIST_${{matrix.branch}}
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}