Skip to content

Publish ref version-1.6.x #98

Publish ref version-1.6.x

Publish ref version-1.6.x #98

name: Publish Docker image
run-name: Publish ref ${{ github.ref_name }}
on:
workflow_dispatch:
inputs:
docker-tags:
description: 'Docker tags'
required: true
base-image:
description: 'Base image'
required: false
workflow_call:
inputs:
raw-docker-tags:
type: string
environment:
type: string
ref:
type: string
secrets:
DOCKERHUB_USER:
required: true
DOCKERHUB_PASSWORD:
required: true
outputs:
digest:
value: ${{ jobs.publish.outputs.digest }}
env:
IMAGE_NAME: ghcr.io/${{ github.repository }}
jobs:
publish:
name: Publish Docker image
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
permissions:
contents: read
packages: write
attestations: write
id-token: write
outputs:
digest: ${{ steps.push.outputs.digest }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- uses: regclient/actions/regctl-installer@4d6888fcc4842c9630f60ebc91715a45dd9bd7a3
- uses: proudust/gh-describe@70f72d4f6304ea053cf5a3d71c36211d5acc0c73
id: ghd
with:
commit-ish: ${{ inputs.ref || github.sha}}
- name: Prepare base image and node version
run: |
BASE_IMAGE=${{ inputs.base-image }}
BASE_IMAGE=${BASE_IMAGE:-$(head -n1 docker/Dockerfile | cut -d= -f2-)}
echo "base-image=$BASE_IMAGE" >> "$GITHUB_OUTPUT"
echo "base-image-digest=$(regctl manifest digest $BASE_IMAGE)" >> "$GITHUB_OUTPUT"
echo "node-version=$(echo ${{ steps.ghd.outputs.describe }} | cut -c 2-)" >> "$GITHUB_OUTPUT"
id: versions
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
cache: 'sbt'
- uses: sbt/setup-sbt@v1
- name: Build tarballs for docker
run: sbt --batch -Dproject.version=${{ steps.versions.outputs.node-version }} buildTarballsForDocker
- name: Extract image name and tags from workflow_call inputs
if: inputs.raw-docker-tags != ''
env:
RAW_DOCKER_TAGS: ${{ inputs.raw-docker-tags }}
run: |
echo "TAGS=$RAW_DOCKER_TAGS" >> "$GITHUB_ENV"
{
echo 'IMAGES<<EOF'
echo ${{ env.IMAGE_NAME }}
echo wavesplatform/wavesnode
echo EOF
} >> "$GITHUB_ENV"
- name: Extract image name and tags from workflow_dispatch inputs
if: github.event_name == 'workflow_dispatch'
run: |
{
echo 'TAGS<<EOF'
echo ${{ inputs.docker-tags }} | tr ',' '\n' | sed -e 's/^/type=raw,value=/'
echo type=sha
echo EOF
} >> "$GITHUB_ENV"
echo "IMAGES=${{ env.IMAGE_NAME }}" >> "$GITHUB_ENV"
- name: Prepare annotations
run: |
{
echo 'annotations<<EOF'
echo org.opencontainers.image.source=https://github.com/${{ github.repository }}/tree/${{ steps.ghd.outputs.sha }}/docker
echo org.opencontainers.image.licenses=MIT
echo org.opencontainers.image.description=Waves Node
echo org.opencontainers.image.base.name=${{ steps.versions.outputs.base-image }}
echo org.opencontainers.image.base.digest=${{ steps.versions.outputs.base-image-digest }}
echo org.opencontainers.image.version=${{ steps.versions.outputs.node-version }}
echo org.opencontainers.image.revision=${{ steps.ghd.outputs.sha }}
echo EOF
} >> "$GITHUB_OUTPUT"
id: annotations
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/login-action@v3
if: inputs.environment != ''
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- uses: docker/setup-buildx-action@v3
- uses: docker/metadata-action@v5
id: meta
env:
DOCKER_METADATA_ANNOTATIONS_LEVELS: index,manifest-descriptor,index-descriptor
with:
images: ${{ env.IMAGES }}
flavor: latest=${{ contains(inputs.docker-tags, 'latest') }}
tags: ${{ env.TAGS }}
annotations: ${{ steps.annotations.outputs.annotations }}
- uses: docker/build-push-action@v6
id: push
with:
context: ./docker
platforms: linux/amd64,linux/arm64
push: true
build-args: baseImage=${{ steps.versions.outputs.base-image }}@${{ steps.versions.outputs.base-image-digest }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
annotations: ${{ steps.meta.outputs.annotations }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Prepare summary
run: |
{
echo '## Image Info'
echo '- This image: `${{ env.IMAGE_NAME }}@${{ steps.push.outputs.digest }}`'
echo '- Base image: `${{ steps.versions.outputs.base-image }}@${{ steps.versions.outputs.base-image-digest }}`'
echo '- Version: `${{ steps.versions.outputs.node-version }}`'
} >> $GITHUB_STEP_SUMMARY