Maybe fix approver pruner demoting prematurely. #219
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
# On every commit, build and push a Docker image to the GitHub Container | |
# registry and to DockerHub. | |
# | |
# The resulting Docker images are tagged with the full commit hash, the git | |
# branch name, the git tag, and the 'latest' tag for the latest commit to | |
# master. | |
# | |
# https://github.com/aibooruorg/aibooru/pkgs/container/aibooru | |
# | |
# https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry | |
# https://docs.github.com/en/packages/managing-github-packages-using-github-actions-workflows/publishing-and-installing-a-package-with-github-actions | |
# https://docs.github.com/en/actions/guides/publishing-docker-images | |
name: Docker Build | |
# https://docs.github.com/en/actions/reference/events-that-trigger-workflows | |
on: | |
push: | |
create: | |
workflow_dispatch: | |
inputs: | |
debug_enabled: | |
type: boolean | |
description: "Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)" | |
required: false | |
default: false | |
# https://docs.github.com/en/actions/reference/authentication-in-a-workflow#permissions-for-the-github_token | |
# https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idpermissions | |
permissions: | |
packages: write | |
jobs: | |
docker-build: | |
runs-on: ubuntu-latest | |
steps: | |
# https://github.com/docker/setup-qemu-action | |
# https://github.com/docker/setup-buildx-action#with-qemu | |
#- name: Set up QEMU | |
# uses: docker/setup-qemu-action@v1 | |
# with: | |
# platforms: arm64 | |
# https://github.com/docker/setup-buildx-action | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
with: | |
config-inline: | | |
[worker.oci] | |
max-parallelism = 2 | |
# https://github.com/docker/login-action | |
# https://github.com/docker/build-push-action/blob/master/docs/advanced/push-multi-registries.md | |
- name: Login to Github Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ github.token }} | |
# Generate Docker tags from Git tags. | |
# https://github.com/docker/metadata-action | |
- name: Generate Docker tags | |
uses: docker/metadata-action@v5 | |
id: metadata | |
with: | |
images: | | |
ghcr.io/aibooruorg/aibooru | |
tags: | | |
type=sha,format=long,prefix= | |
type=ref,event=branch | |
type=ref,event=tag | |
type=ref,event=pr | |
# Tag `latest` on every commit pushed to master | |
# https://github.com/docker/metadata-action/issues/112 | |
flavor: | | |
latest=${{ github.ref == 'refs/heads/master' }} | |
# https://github.com/docker/build-push-action | |
- name: Build image | |
uses: docker/build-push-action@v5 | |
with: | |
push: true | |
tags: ${{ steps.metadata.outputs.tags }} | |
labels: ${{ steps.metadata.outputs.labels }} | |
#platforms: linux/amd64,linux/arm64 | |
platforms: linux/amd64 | |
target: production | |
# https://github.com/docker/build-push-action/blob/master/docs/advanced/cache.md#registry-cache | |
# https://dev.to/pst418/speed-up-multi-stage-docker-builds-in-ci-cd-with-buildkit-s-registry-cache-11gi | |
cache-from: type=registry,ref=ghcr.io/${{ github.repository }}:buildcache | |
cache-to: type=registry,ref=ghcr.io/${{ github.repository }}:buildcache,mode=max | |
build-args: | | |
DOCKER_IMAGE_REVISION=${{ github.sha }} | |
DOCKER_IMAGE_BUILD_DATE=${{ fromJSON(steps.metadata.outputs.json).labels['org.opencontainers.image.created'] }} | |
# Generate Docker tags from Git tags for the development image. | |
- name: Generate Docker tags for development image | |
uses: docker/metadata-action@v5 | |
id: development-metadata | |
with: | |
images: | | |
ghcr.io/aibooruorg/aibooru | |
tags: | | |
type=sha,format=long,prefix=development- | |
type=ref,event=branch,prefix=development- | |
type=ref,event=tag,prefix=development- | |
type=ref,event=pr,prefix=development- | |
type=raw,value=development,enable={{is_default_branch}} | |
flavor: | | |
latest=false | |
# https://github.com/docker/build-push-action | |
- name: Build development image | |
uses: docker/build-push-action@v5 | |
with: | |
push: true | |
tags: ${{ steps.development-metadata.outputs.tags }} | |
labels: ${{ steps.development-metadata.outputs.labels }} | |
#platforms: linux/amd64,linux/arm64 | |
platforms: linux/amd64 | |
target: development | |
# https://github.com/docker/build-push-action/blob/master/docs/advanced/cache.md#registry-cache | |
# https://dev.to/pst418/speed-up-multi-stage-docker-builds-in-ci-cd-with-buildkit-s-registry-cache-11gi | |
cache-from: type=registry,ref=ghcr.io/${{ github.repository }}:buildcache | |
cache-to: type=registry,ref=ghcr.io/${{ github.repository }}:buildcache,mode=max | |
build-args: | | |
DOCKER_IMAGE_REVISION=${{ github.sha }} | |
DOCKER_IMAGE_BUILD_DATE=${{ fromJSON(steps.development-metadata.outputs.json).labels['org.opencontainers.image.created'] }} | |
# https://github.com/marketplace/actions/debugging-with-ssh | |
- name: Setup tmate session | |
uses: mxschmitt/action-tmate@v3 | |
if: ${{ always() && (github.event_name == 'workflow_dispatch' && inputs.debug_enabled) }} | |
with: | |
limit-access-to-actor: true | |
deploy-beta: | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/beta' | |
needs: docker-build | |
concurrency: deploy-beta | |
environment: | |
name: beta | |
url: https://beta.aibooru.online | |
steps: | |
# https://github.com/marketplace/actions/kubectl-tool-installer | |
- name: Install Kubectl | |
uses: azure/setup-kubectl@v3 | |
with: | |
version: v1.21.5 | |
- name: Configure Kubectl | |
run: | | |
mkdir -p ~/.kube | |
echo "$KUBECONFIG_YAML" > ~/.kube/config | |
env: | |
KUBECONFIG_YAML: ${{secrets.KUBECONFIG_YAML}} | |
- name: Deploy to Betabooru | |
run: | | |
kubectl rollout restart deploy/betabooru -n danbooru | |
deploy-production: | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/production' | |
needs: docker-build | |
concurrency: deploy-production | |
environment: | |
name: production | |
url: https://aibooru.online | |
steps: | |
- name: Install Kubectl | |
uses: azure/setup-kubectl@v3 | |
with: | |
version: v1.21.5 | |
- name: Configure Kubectl | |
run: | | |
mkdir -p ~/.kube | |
echo "$KUBECONFIG_YAML" > ~/.kube/config | |
env: | |
KUBECONFIG_YAML: ${{secrets.KUBECONFIG_YAML}} | |
- name: Deploy to Production | |
run: | | |
kubectl rollout restart deploy/danbooru deploy/jobs deploy/cron deploy/discord -n danbooru | |
tag-production: | |
runs-on: ubuntu-latest | |
needs: deploy-production | |
permissions: | |
contents: write | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set env | |
run: echo "NOW=$(date +'%Y.%m.%d_%H.%M.%S-utc')" >> $GITHUB_ENV | |
- name: Create tag | |
uses: rickstaa/action-create-tag@v1 | |
id: tag_create | |
with: | |
tag: production-${{ env.NOW }} | |
message: "Production deployment" | |
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} | |
gpg_passphrase: ${{ secrets.GPG_PASSPHRASE }} |