Kon/.gitea/workflows/build.yml
2024-08-01 04:47:03 +00:00

57 lines
2.3 KiB
YAML

name: Build and push container image
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-22.04-node
steps:
- name: Set up Docker environment
run: |
apt update && apt upgrade -y && apt install -y apt-transport-https ca-certificates curl zstd gnupg lsb-release
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo \
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian \
$(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
apt update && apt install -y docker-ce docker-ce-cli containerd.io
- name: Checkout branch
uses: https://github.com/actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
- name: Login to Gitea
uses: https://github.com/docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3
with:
registry: git.toast-server.net
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Set up Docker Buildx
uses: https://github.com/docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db # v3
- name: Build and push image
uses: https://github.com/docker/build-push-action@ca052bb54ab0790a636c9b5f226502c73d547a25 # v5.4.0
with:
context: .
platforms: linux/amd64
push: true
tags: git.toast-server.net/toast/kon:main
build-args: CARGO_TOKEN=${{ secrets.CARGO_TOKEN }}
cache-from: type=registry,ref=git.toast-server.net/toast/kon:main
cache-to: type=inline
- name: Deploy update
uses: https://github.com/appleboy/ssh-action@029f5b4aeeeb58fdfe1410a5d17f967dacf36262 # v1.0.3
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
passphrase: ${{ secrets.SSH_PASSPHRASE }}
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
cd kon && docker compose pull bot && \
docker compose down bot && docker compose up -d bot && \
docker image prune -f && docker system prune -f