72 lines
2.8 KiB
YAML
72 lines
2.8 KiB
YAML
name: Build and push container image
|
|
on:
|
|
push:
|
|
branches:
|
|
- master
|
|
jobs:
|
|
build:
|
|
runs-on: rust-ci
|
|
steps:
|
|
- name: Install Node21
|
|
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
|
|
with:
|
|
node-version: 21.7.1
|
|
check-latest: false
|
|
architecture: x64
|
|
|
|
- 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@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
|
|
|
|
- name: Login to Gitea
|
|
uses: https://github.com/docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3
|
|
with:
|
|
registry: git.toast-server.net
|
|
username: ${{ secrets.DOCKER_USERNAME }}
|
|
password: ${{ secrets.DOCKER_TOKEN }}
|
|
|
|
- name: Retrieve cache
|
|
uses: https://github.com/actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 # v4.0.1
|
|
with:
|
|
path: |
|
|
~/.cargo/bin/
|
|
~/.cargo/registry/index/
|
|
~/.cargo/registry/cache/
|
|
~/.cargo/git/db/
|
|
target/
|
|
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: https://github.com/docker/setup-buildx-action@0d103c3126aa41d772a8362f6aa67afac040f80c # v3
|
|
|
|
- name: Build and push image
|
|
uses: https://github.com/docker/build-push-action@af5a7ed5ba88268d5278f7203fb52cd833f66d6e # v5.2.0
|
|
with:
|
|
context: .
|
|
platforms: linux/amd64
|
|
push: true
|
|
tags: git.toast-server.net/toast/kon:main
|
|
cache-to: type=local,dest=/tmp/.build-cache
|
|
cache-from: type=local,src=/tmp/.buildx-cache,mode=max
|
|
|
|
- name: Container deployment
|
|
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 && \
|
|
docker compose down bot --remove-orphans && docker compose up -d bot && \
|
|
docker image prune -f && docker system prune -f
|