Skip to content

Commit 8462076

Browse files
authored
feat(CD): 👷 Continuous delivery (#27)
* 👷 Add Dockerfile and Compose configuration for containerized setup * 👷 Add workflow to build and push Docker images * 👷 Add deployment workflow for Coolify integration * 👷 Set explicit permissions for GitHub workflows * 💚 Fix Coolify deployment workflow * 👷 Update permissions for GitHub workflows
1 parent 520fc10 commit 8462076

7 files changed

Lines changed: 131 additions & 0 deletions

File tree

.github/workflows/CI.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,21 @@ concurrency:
1212

1313
jobs:
1414
quality:
15+
permissions:
16+
contents: read
1517
uses: ./.github/workflows/quality.yml
18+
docker:
19+
needs: quality
20+
permissions:
21+
contents: read
22+
packages: write
23+
id-token: write
24+
uses: ./.github/workflows/docker.yml
25+
deploy:
26+
permissions: {}
27+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
28+
needs: docker
29+
uses: ./.github/workflows/deploy.yml
30+
secrets:
31+
COOLIFY_WEBHOOK: ${{ secrets.COOLIFY_WEBHOOK }}
32+
COOLIFY_TOKEN: ${{ secrets.COOLIFY_TOKEN }}

.github/workflows/autofix.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ permissions:
99

1010
jobs:
1111
autofix:
12+
permissions:
13+
contents: read
1214
runs-on: ubuntu-latest
1315
steps:
1416
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6

.github/workflows/deploy.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: deploy.yml
2+
on:
3+
workflow_call:
4+
secrets:
5+
COOLIFY_WEBHOOK:
6+
required: true
7+
COOLIFY_TOKEN:
8+
required: true
9+
10+
permissions: {}
11+
12+
jobs:
13+
deploy:
14+
runs-on: ubuntu-latest
15+
environment: coolify
16+
name: Deploy to Coolify
17+
steps:
18+
- name: Deploy
19+
run: |
20+
curl --request GET '${{ secrets.COOLIFY_WEBHOOK }}' --header 'Authorization: Bearer ${{ secrets.COOLIFY_TOKEN }}'

.github/workflows/docker.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Build and Push Docker Image
2+
3+
on: workflow_call
4+
5+
env:
6+
REGISTRY: ghcr.io
7+
IMAGE_NAME: ${{ github.repository }}
8+
9+
permissions:
10+
contents: read
11+
packages: write
12+
id-token: write
13+
14+
jobs:
15+
docker:
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
19+
packages: write
20+
id-token: write
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
24+
25+
- name: Set up Docker Buildx
26+
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
27+
28+
- name: Log into registry ${{ env.REGISTRY }}
29+
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
30+
with:
31+
registry: ${{ env.REGISTRY }}
32+
username: ${{ github.actor }}
33+
password: ${{ secrets.GITHUB_TOKEN }}
34+
35+
- name: Extract Docker metadata
36+
id: meta
37+
uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0
38+
with:
39+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
40+
tags: |
41+
type=ref,event=branch
42+
type=ref,event=pr
43+
type=ref,event=tag
44+
type=sha
45+
46+
- name: Build and push Docker image
47+
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
48+
with:
49+
context: .
50+
push: true
51+
tags: ${{ steps.meta.outputs.tags }}
52+
labels: ${{ steps.meta.outputs.labels }}
53+
cache-from: type=gha
54+
cache-to: type=gha,mode=max

.github/workflows/quality.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ on:
44
workflow_call:
55
workflow_dispatch:
66

7+
permissions:
8+
contents: read
9+
710
jobs:
811
quality:
912
runs-on: ubuntu-latest

Dockerfile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
ARG PYTHON_VERSION=3.13
2+
FROM python:${PYTHON_VERSION}-slim-bookworm AS python-base
3+
4+
ENV PYTHONDONTWRITEBYTECODE=1
5+
ENV PYTHONUNBUFFERED=1
6+
7+
RUN pip install uv
8+
9+
WORKDIR /app
10+
COPY pyproject.toml uv.lock ./
11+
12+
ENV UV_NO_DEV=1
13+
RUN uv export -o requirements.txt
14+
15+
FROM python:${PYTHON_VERSION}-bookworm AS app
16+
17+
ENV PYTHONDONTWRITEBYTECODE=1
18+
ENV PYTHONUNBUFFERED=1
19+
20+
WORKDIR /app
21+
22+
RUN adduser -u 8192 --disabled-password --gecos "" appuser && chown -R appuser /app
23+
24+
COPY --from=python-base --chown=appuser /app/requirements.txt ./
25+
COPY LICENSE ./
26+
RUN pip install -r requirements.txt
27+
28+
COPY src/ ./src
29+
USER appuser
30+
31+
CMD ["python", "-m", "src"]

compose.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
services:
2+
bot:
3+
build: .
4+
env_file: .env

0 commit comments

Comments
 (0)