feat: dockerize and auto-deploy on push
Build and Push Docker Image / build (push) Successful in 4m33s
Continuous integration / Check (push) Successful in 1m33s
Continuous integration / Test Suite (push) Successful in 2m24s
Continuous integration / Rustfmt (push) Successful in 27s
Continuous integration / Clippy (push) Successful in 1m30s

Multi-stage image built offline with the sqlx cache (migrations are
already embedded in the binary) on a slim runtime, and a Gitea
Actions workflow that pushes to the registry and triggers the shared
vemmarcar deploy webhook, mirroring the up-track pipeline.
This commit is contained in:
Alexandre Possebom
2026-07-28 19:40:12 -03:00
parent 7df13e4104
commit a786c49572
3 changed files with 121 additions and 0 deletions
+6
View File
@@ -0,0 +1,6 @@
target
.env
*.log
.DS_Store
docs
BUGS.md
+98
View File
@@ -0,0 +1,98 @@
name: Build and Push Docker Image
on:
push:
branches:
- master
tags:
- '*'
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Record start time
run: echo "BUILD_START=$(date +%s)" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Gitea Container Registry
uses: docker/login-action@v3
with:
registry: git.possebom.com
username: ${{ gitea.actor }}
password: ${{ secrets.REGISTRY_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: git.possebom.com/${{ gitea.repository }}
tags: |
type=ref,event=branch
type=ref,event=tag
type=raw,value=latest,enable=${{ gitea.ref == 'refs/heads/master' }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
- name: Trigger deploy webhook
run: |
echo "Calling webhook at http://10.2.0.100:9024/hooks/deploy-vemmarcar"
HTTP_CODE=$(curl -sv -o /tmp/webhook-response.txt -w "%{http_code}" \
-X POST \
-H "X-Webhook-Token: 1c3312f18fb477f609c3f2d1e1837026260c04f57d64299a3d4a4f411eec5ceb" \
http://10.2.0.100:9024/hooks/deploy-vemmarcar 2>&1 | tee /tmp/webhook-debug.txt | tail -1)
echo "--- Response body ---"
cat /tmp/webhook-response.txt || true
echo ""
echo "--- HTTP code: $HTTP_CODE ---"
if [ "$HTTP_CODE" != "200" ]; then
echo "--- Debug output ---"
cat /tmp/webhook-debug.txt || true
exit 1
fi
- name: Notify Telegram
if: always()
run: |
STATUS="${{ job.status }}"
if [ "$STATUS" = "success" ]; then
EMOJI="✅"
else
EMOJI="❌"
fi
BUILD_END=$(date +%s)
DURATION=$((BUILD_END - BUILD_START))
MINUTES=$((DURATION / 60))
SECONDS=$((DURATION % 60))
if [ $MINUTES -gt 0 ]; then
TIME_STR="${MINUTES}m ${SECONDS}s"
else
TIME_STR="${SECONDS}s"
fi
SHORT_SHA="${{ gitea.sha }}"
SHORT_SHA="${SHORT_SHA:0:7}"
MESSAGE="${EMOJI} *Build ${STATUS}*
📦 *Repo:* ${{ gitea.repository }}
🔀 *Branch:* ${{ gitea.ref_name }}
👤 *Author:* ${{ gitea.actor }}
📝 *Commit:* \`${SHORT_SHA}\`
⏱️ *Tempo:* ${TIME_STR}"
curl -s -X POST "https://api.telegram.org/bot${{ secrets.TELEGRAM_TOKEN }}/sendMessage" \
-d chat_id="${{ secrets.TELEGRAM_CHAT_ID }}" \
-d parse_mode="Markdown" \
-d text="$MESSAGE"
+17
View File
@@ -0,0 +1,17 @@
FROM rust:1-bookworm AS builder
WORKDIR /app
COPY Cargo.toml Cargo.lock ./
COPY src/ src/
COPY migrations/ migrations/
COPY .sqlx/ .sqlx/
# Sem banco no build: as queries vêm do cache do sqlx (.sqlx) e as
# migrations são embutidas no binário pelo sqlx::migrate!.
ENV SQLX_OFFLINE=true
RUN cargo build --release --locked
FROM debian:bookworm-slim
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY --from=builder /app/target/release/schdlr .
EXPOSE 3000
CMD ["./schdlr"]