Kon/.gitea/workflows/build.yml

99 lines
2.7 KiB
YAML
Raw Normal View History

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