Kon/.gitea/workflows/build.yml
pomni32 45d7a750d6
All checks were successful
Build and push Docker image / build (push) Successful in 2m45s
Build and push Docker image / deploy (push) Successful in 38s
comeonnnnn
2024-12-02 08:46:09 -05:00

98 lines
2.7 KiB
YAML

name: Build and push Docker image
on:
push:
branches:
- master
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-22.04
env:
RUNNER_TOOL_CACHE: /toolcache
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Checkout
uses: actions/checkout@v4
- name: Install zstd
run: sudo apt-get update && sudo apt-get install -y zstd
- name: Generate cache key
id: cargo-cache-key
run: |
find ./Cargo.lock -type f -exec sha256sum {} + | sha256sum > hash.txt
cat hash.txt
- name: Cache
uses: actions/cache@v4
id: cache
with:
save-always: true
path: |
$HOME/.cargo/bin/
$HOME/.cargo/git/
$HOME/.cargo/registry/index/
$HOME/.cargo/registry/cache/
target/
key: ${{ runner.os }}-cache-${{ steps.cargo-cache-key.outputs.hash }}
- name: Login to Gitea
uses: docker/login-action@v3
with:
registry: git.toast-server.net
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Set up Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
rustflags: -C target-feature=-crt-static
- name: Install zigbuild
run: |
pip3 install ziglang
cargo install --locked cargo-zigbuild
- name: Compile
run: |
rustup target add x86_64-unknown-linux-musl
export GIT_COMMIT_HASH=${{ github.sha }} && \
export GIT_COMMIT_BRANCH=${{ github.ref_name }} && \
cargo zigbuild --target x86_64-unknown-linux-musl --locked -rF production
- name: Build and push image
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64
push: true
tags: git.toast-server.net/toast/kon:master
cache-from: type=registry,ref=git.toast-server.net/toast/kon:cache
cache-to: type=registry,ref=git.toast-server.net/toast/kon:cache,mode=max,image-manifest=true,oci-mediatypes=true
deploy:
runs-on: host
needs: build
steps:
- name: Deploy update
uses: appleboy/ssh-action@v1.2.0
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 up -d bot --force-recreate && \
docker system prune -f