ci/cd: added dockerfile and workflows
This commit is contained in:
parent
6e391d2875
commit
57d8271c5d
|
@ -0,0 +1,57 @@
|
|||
name: Build and Deploy
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- "master"
|
||||
paths-ignore:
|
||||
- ".sqlx"
|
||||
- "**.md"
|
||||
|
||||
jobs:
|
||||
build-docker:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Cache Docker layers
|
||||
uses: https://github.com/actions/cache@v3
|
||||
with:
|
||||
path: |
|
||||
/tmp/.buildx-cache
|
||||
key: ${{ runner.os }}-buildx-admin_worker-${{ gitea.sha }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-buildx-admin_worker-
|
||||
|
||||
- name: Login to Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: git.nerdcult.net/nerdcult
|
||||
username: nerdcultbot
|
||||
password: ${{ secrets.NerdcultBotToken }}
|
||||
|
||||
- name: Build and Push
|
||||
uses: docker/build-push-action@v5
|
||||
env:
|
||||
ACTIONS_RUNTIME_TOKEN: ''
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
tags: git.nerdcult.net/nerdcult/nerdcult_admin_worker:latest
|
||||
cache-from: type=local,src=/tmp/.buildx-cache
|
||||
cache-to: type=local,dest=/tmp/.buildx-cache-new
|
||||
|
||||
- name: Rotate the cache
|
||||
run: |
|
||||
rm -rf /tmp/.buildx-cache
|
||||
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
|
||||
|
||||
- name: Deploy
|
||||
env:
|
||||
TOWER_TOKEN: ${{ secrets.WatchtowerToken}}
|
||||
TOWER_URI: ${{ secrets.WatchtowerURI}}
|
||||
run: |
|
||||
curl -H "Authorization: Bearer $TOWER_TOKEN" $TOWER_URI
|
|
@ -0,0 +1,28 @@
|
|||
FROM rust:latest as build
|
||||
|
||||
# 1. Create a new empty shell project
|
||||
RUN USER=root cargo new --bin nerdcult_admin_worker
|
||||
WORKDIR /nerdcult_admin_worker
|
||||
|
||||
# 2. Copy our manifests
|
||||
COPY ./Cargo.lock ./Cargo.lock
|
||||
COPY ./Cargo.toml ./Cargo.toml
|
||||
|
||||
# 3. Build only the dependencies to cache them
|
||||
RUN cargo build --release
|
||||
RUN rm src/*.rs
|
||||
|
||||
# 4. Now that the dependency is built, copy your source code
|
||||
COPY ./src ./src
|
||||
COPY .sqlx .sqlx
|
||||
|
||||
# 5. Build for release.
|
||||
RUN rm ./target/release/deps/admin_worker*
|
||||
|
||||
RUN SQLX_OFFLINE=true NC_AW_BACKUP_PATH=/data/backup NC_AW_HOST_PATH=/host cargo build --release
|
||||
|
||||
FROM debian:bookworm-slim
|
||||
|
||||
COPY --from=build /nerdcult_admin_worker/target/release/admin-worker /bin/admin-worker
|
||||
|
||||
CMD ["/bin/admin_worker"]
|
Loading…
Reference in New Issue