Kon/.gitea/workflows/build.yml

99 lines
2.7 KiB
YAML
Raw Normal View History

2024-09-22 02:49:01 +10:00
name: Build and push Docker image
2024-03-12 14:30:27 +11:00
2023-12-08 22:25:57 +11:00
on:
push:
branches:
- master
2024-03-12 14:30:27 +11:00
2024-09-22 02:49:01 +10:00
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
2024-12-07 15:50:52 +11:00
env:
CARGO_TERM_COLOR: always
RUNNER_TOOL_CACHE: /toolcache
2023-12-08 22:25:57 +11:00
jobs:
build:
2024-08-15 12:28:23 +10:00
runs-on: ubuntu-22.04
2024-09-22 02:49:01 +10:00
2023-12-08 22:25:57 +11:00
steps:
2024-09-22 02:49:01 +10:00
- name: Set up Docker Buildx
2024-12-02 08:46:09 -05:00
uses: docker/setup-buildx-action@v3
2024-09-22 02:49:01 +10:00
- name: Checkout
2024-12-03 00:43:08 +11:00
uses: actions/checkout@v4
2024-09-22 04:17:36 +10:00
- 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
2024-09-22 02:49:01 +10:00
- name: Cache
2024-12-03 00:43:08 +11:00
uses: actions/cache@v4
2024-09-22 02:49:01 +10:00
id: cache
with:
2024-09-22 04:41:15 +10:00
save-always: true
2024-09-22 02:49:01 +10:00
path: |
$HOME/.cargo/bin/
$HOME/.cargo/git/
$HOME/.cargo/registry/index/
$HOME/.cargo/registry/cache/
target/
2024-12-07 15:50:52 +11:00
key: ${{ runner.os }}-cargo-${{ steps.cargo-cache-key.outputs.hash }}
restore-keys: ${{ runner.os }}-cargo-
2024-09-22 02:49:01 +10:00
2023-12-08 22:25:57 +11:00
- name: Login to Gitea
2024-12-03 00:43:08 +11:00
uses: docker/login-action@v3
2023-12-08 22:25:57 +11:00
with:
registry: git.toast-server.net
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
2024-09-22 02:49:01 +10:00
- name: Set up Rust toolchain
2024-12-03 00:43:08 +11:00
uses: actions-rust-lang/setup-rust-toolchain@v1
2024-09-22 02:49:01 +10:00
with:
rustflags: -C target-feature=-crt-static
- name: Install zigbuild
run: |
2024-09-22 04:17:36 +10:00
pip3 install ziglang
2024-09-22 02:49:01 +10:00
cargo install --locked cargo-zigbuild
- name: Compile
run: |
rustup target add x86_64-unknown-linux-musl
export GIT_COMMIT_HASH=${{ github.sha }} && \
cargo zigbuild --target x86_64-unknown-linux-musl --locked -rF production
2024-01-08 00:28:30 +11:00
2023-12-08 22:25:57 +11:00
- name: Build and push image
2024-12-03 00:43:08 +11:00
uses: docker/build-push-action@v6
2023-12-08 22:25:57 +11:00
with:
2024-01-08 03:37:48 +11:00
context: .
2023-12-08 22:25:57 +11:00
platforms: linux/amd64
push: true
2024-09-22 02:49:01 +10:00
tags: git.toast-server.net/toast/kon:master
2024-09-22 04:17:36 +10:00
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
2024-08-15 12:28:23 +10:00
deploy:
2024-09-22 04:41:15 +10:00
runs-on: host
2024-08-15 12:28:23 +10:00
needs: build
steps:
2024-05-03 05:26:05 +10:00
- name: Deploy update
2024-12-07 16:01:20 +11:00
uses: appleboy/ssh-action@v1.2.0
2024-03-11 10:30:52 +11:00
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
passphrase: ${{ secrets.SSH_PASSPHRASE }}
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
2024-04-08 18:08:37 -04:00
cd kon && docker compose pull bot && \
2024-08-15 12:58:26 +10:00
docker compose up -d bot --force-recreate && \
docker system prune -f