Skip to content

Merge pull request #55 from obeone/codex/add-options-for-html-element… #228

Merge pull request #55 from obeone/codex/add-options-for-html-element…

Merge pull request #55 from obeone/codex/add-options-for-html-element… #228

name: Build and Push Docker image
on:
push:
branches:
- main
workflow_dispatch:
pull_request:
types: [opened, synchronize, reopened, edited]
release:
types: [published]
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write # For cosign
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
if: ${{ (github.event_name == 'push' && github.ref == 'refs/heads/main') || (github.event_name == 'workflow_dispatch') || github.event_name == 'release' }}
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Log in to Docker Hub
if: ${{ (github.event_name == 'push' && github.ref == 'refs/heads/main') || (github.event_name == 'workflow_dispatch') || github.event_name == 'release' }}
uses: docker/login-action@v2
with:
registry: docker.io
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set Docker image tags and build args
id: docker_tags
run: |
TAGS="ghcr.io/obeone/crawler-to-md:latest\ndocker.io/obeoneorg/crawler-to-md:latest"
if [ "${{ github.event_name }}" = "release" ] && [ -n "${{ github.event.release.tag_name }}" ]; then
TAGS="$TAGS\nghcr.io/obeone/crawler-to-md:${{ github.event.release.tag_name }}\ndocker.io/obeoneorg/crawler-to-md:${{ github.event.release.tag_name }}"
fi
APP_VERSION=0.0.0
if [ "${{ github.event_name }}" = "release" ] && [ -n "${{ github.event.release.tag_name }}" ]; then
APP_VERSION=${{ github.event.release.tag_name }}
fi
echo "tags<<EOF" >> $GITHUB_OUTPUT
echo -e "$TAGS" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "build_args<<EOF" >> $GITHUB_OUTPUT
echo -e "APP_VERSION=$APP_VERSION" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Build and push Docker image
uses: docker/build-push-action@v5
id: docker_build
with:
context: .
file: ./Dockerfile
push: ${{ (github.event_name == 'push' && github.ref == 'refs/heads/main') || (github.event_name == 'workflow_dispatch') || github.event_name == 'release' }}
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ${{ steps.docker_tags.outputs.tags }}
build-args: ${{ steps.docker_tags.outputs.build_args }}
platforms: linux/amd64,linux/arm64
- name: Set up cosign
if: ${{ (github.event_name == 'push' && github.ref == 'refs/heads/main') || (github.event_name == 'workflow_dispatch') || github.event_name == 'release' }}
uses: sigstore/cosign-installer@v3
- name: Sign the container image with cosign
if: ${{ (github.event_name == 'push' && github.ref == 'refs/heads/main') || (github.event_name == 'workflow_dispatch') || github.event_name == 'release' }}
run: |
cosign sign --yes ghcr.io/obeone/crawler-to-md@${DIGEST}
cosign sign --yes docker.io/obeoneorg/crawler-to-md@${DIGEST}
env:
COSIGN_EXPERIMENTAL: true
DIGEST: ${{ steps.docker_build.outputs.digest }}
- name: Update Docker Hub description
if: ${{ (github.event_name == 'push' && github.ref == 'refs/heads/main') || (github.event_name == 'workflow_dispatch') || github.event_name == 'release' }}
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
repository: obeoneorg/crawler-to-md