push container #721
This file contains 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
name: push container | |
on: | |
push: | |
branches: master | |
schedule: | |
- cron: "30 9 * * 2,5" | |
workflow_dispatch: | |
inputs: | |
src_ref: | |
description: "The branch/tag for which the dispatch is sent from dreambbs project" | |
required: true | |
default: "refs/tags/stable" | |
src_sha: | |
description: "The commit SHA for which the dispatch is sent from dreambbs project" | |
required: false | |
default: "" | |
env: | |
SRC_SHA: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.src_sha || '' }} | |
SRC_REF: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.src_ref || format('refs/{0}/{1}', 'tags', 'stable') }} | |
SRC_REF_NEXT: >- | |
${{ github.event_name == 'workflow_dispatch' && '{}' || '{"refs/tags/stable": "refs/heads/master"}' }} | |
jobs: | |
main: | |
if: "!contains(github.event.head_commit.message, 'skip-ci')" | |
runs-on: ubuntu-22.04 | |
steps: | |
- | |
name: Request building for other branches | |
if: ${{ fromJSON(env.SRC_REF_NEXT)[env.SRC_REF] }} | |
run: | | |
curl \ | |
-X POST \ | |
-u "${{ secrets.PAT_USERNAME}}:${{secrets.PAT_TOKEN}}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
-H "Content-Type: application/json" \ | |
https://api.github.com/repos/$REPO/actions/workflows/$WORKFLOW_ID/dispatches \ | |
-d "$(jq -n -jc '{ | |
"ref": "refs/heads/master", | |
"inputs": {"src_ref": $ENV.src_ref, "src_sha": ""} | |
}')" | |
env: | |
REPO: ${{ github.repository }} | |
WORKFLOW_ID: 'push_container.yml' | |
src_ref: ${{ fromJSON(env.SRC_REF_NEXT)[env.SRC_REF] }} | |
- | |
name: Checkout | |
uses: actions/checkout@v4 | |
- | |
name: Get current date | |
id: date | |
run: echo "date=$(date +'%Y%m%d')" >> $GITHUB_OUTPUT | |
- | |
name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- | |
name: Cache Docker layers | |
uses: actions/cache@v4 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-buildx- | |
- | |
name: Login to DockerHub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- | |
name: Getting Commit Information from DreamBBS | |
id: src_info | |
run: | | |
SRC_REF_NAME="${SRC_REF##*/}" | |
SRC_REF_INFO="$(curl \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
"https://api.github.com/repos/ccns/dreambbs/git/$SRC_REF")" | |
SRC_SHA_LATEST="$(jq -r '.object.sha' <<< "$SRC_REF_INFO")" | |
if [ -z "$SRC_SHA" ]; then | |
SRC_SHA="$SRC_SHA_LATEST" | |
fi | |
echo "SRC_REF_NAME=$SRC_REF_NAME" >> $GITHUB_ENV | |
echo "SRC_SHA_LATEST=$SRC_SHA_LATEST" >> $GITHUB_ENV | |
echo "SRC_SHA=$SRC_SHA" >> $GITHUB_ENV | |
echo "SRC_REF_NAME=$SRC_REF_NAME" >> $GITHUB_OUTPUT | |
echo "SRC_SHA_LATEST=$SRC_SHA_LATEST" >> $GITHUB_OUTPUT | |
echo "SRC_SHA=$SRC_SHA" >> $GITHUB_OUTPUT | |
- | |
name: Generate Docker metadata | |
id: docker_meta | |
uses: docker/metadata-action@v5 | |
with: | |
# list of Docker images to use as base name for tags | |
images: ${{ secrets.DOCKERHUB_REPO_OWNER }}/imagedreambbs | |
# generate Docker tags based on the following events/attributes | |
tags: | | |
latest,enable=${{ env.IS_DEFAULT_REF }} | |
${{ steps.date.outputs.date }},enable=${{ env.IS_DEFAULT_REF }} | |
${{ env.SRC_REF_NAME }} | |
${{ env.SRC_REF_NAME }}-latest | |
${{ env.SRC_REF_NAME }}-${{ steps.date.outputs.date }} | |
env: | |
IS_DEFAULT_REF: ${{ env.SRC_REF_NAME == 'stable' }} | |
- | |
name: Build and push | |
id: docker_build | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
push: true | |
build-args: | | |
"SRC_REF_NAME=${{ env.SRC_REF_NAME }}" | |
"SRC_SHA=${{ env.SRC_SHA }}" | |
"SRC_REF=${{ env.SRC_REF }}" | |
tags: ${{ steps.docker_meta.outputs.tags }} | |
cache-from: type=local,src=/tmp/.buildx-cache | |
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max | |
- | |
name: Image digest | |
run: echo ${{ steps.docker_build.outputs.digest }} | |
- | |
# Temp fix | |
# https://github.com/docker/build-push-action/issues/252 | |
# https://github.com/moby/buildkit/issues/1896 | |
name: Move cache | |
run: | | |
rm -rf /tmp/.buildx-cache | |
mv /tmp/.buildx-cache-new /tmp/.buildx-cache | |
- | |
name : Add Notification in bbs-dev in CCNS Discord | |
uses: sarisia/actions-status-discord@v1 | |
if: always() | |
with: | |
webhook: ${{ secrets.DISCORD_WEBHOOK }} | |
title: ${{ github.workflow }} (${{ steps.src_info.outputs.SRC_REF_NAME }}) |