From 722e67d8a4964ae8e73da7840df1aa44b6c8277b Mon Sep 17 00:00:00 2001 From: Pablo Date: Tue, 21 Jan 2025 11:57:46 +0100 Subject: [PATCH] import from original repo Signed-off-by: Pablo --- .github/workflows/docker.yaml | 81 +++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 .github/workflows/docker.yaml diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml new file mode 100644 index 000000000..29c16e130 --- /dev/null +++ b/.github/workflows/docker.yaml @@ -0,0 +1,81 @@ +name: Docker + +on: + push: + branches: + - master + tags: + - "[0-9]+.[0-9]+.[0-9]+" + - "[0-9]+.[0-9]+.[0-9]+-dev.[0-9]+" + pull_request: + +jobs: + docker: + name: Docker + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + # Required for correctly populating ldflags + fetch-depth: 0 + + - name: Calculate Docker image tags + id: tags + env: + DOCKER_IMAGES: "ghcr.io/${{ github.repository }}" + run: | + case $GITHUB_REF in + refs/tags/*) VERSION=${GITHUB_REF#refs/tags/};; + refs/heads/*) VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g');; + refs/pull/*) VERSION=pr-${{ github.event.number }};; + *) VERSION=sha-${GITHUB_SHA::8};; + esac + + TAGS=() + for image in $DOCKER_IMAGES; do + TAGS+=("${image}:${VERSION}") + + if [[ "${{ github.event.repository.default_branch }}" == "$VERSION" ]]; then + TAGS+=("${image}:latest") + fi + done + + echo "version=${VERSION}" >> $GITHUB_OUTPUT + IFS=, ; echo "tags=${TAGS[*]}" >> $GITHUB_OUTPUT + echo "commit_hash=${GITHUB_SHA::8}" >> $GITHUB_OUTPUT + echo "build_date=$(git show -s --format=%cI)" >> $GITHUB_OUTPUT + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ github.token }} + if: github.event_name == 'push' + + - name: Build and push + uses: docker/build-push-action@v2 + with: + push: ${{ github.event_name == 'push' }} + tags: ${{ steps.tags.outputs.tags }} + context: . + build-args: | + VERSION=${{ steps.tags.outputs.version }} + COMMIT_HASH=${{ steps.tags.outputs.commit_hash }} + BUILD_DATE=${{ steps.tags.outputs.build_date }} + labels: | + org.opencontainers.image.title=${{ github.event.repository.name }} + org.opencontainers.image.description=${{ github.event.repository.description }} + org.opencontainers.image.url=${{ github.event.repository.html_url }} + org.opencontainers.image.source=${{ github.event.repository.clone_url }} + org.opencontainers.image.version=${{ steps.tags.outputs.version }} + org.opencontainers.image.created=${{ steps.tags.outputs.build_date }} + org.opencontainers.image.revision=${{ github.sha }} + org.opencontainers.image.licenses=${{ github.event.repository.license.spdx_id }} + org.opencontainers.image.vendor=Banzai Cloud + org.opencontainers.image.documentation=https://banzaicloud.com/docs/pipeline/overview/