Added CI/CD task to automatically build and deploy the docker image

This commit is contained in:
Anselme 2026-10-01 15:36:24 +02:00
parent d955a7a801
commit 5f61a45383
3 changed files with 48 additions and 24 deletions

View File

@ -0,0 +1,33 @@
name: Build and publish Docker image
on:
push:
branches:
- master
jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Derive registry host and image name
id: registry
run: |
host="$(printf '%s' "${{ gitea.server_url }}" | sed -E 's#^[a-zA-Z][a-zA-Z0-9+.-]*://##; s#/.*$##')"
image="$(printf '%s' "${{ gitea.repository }}" | tr '[:upper:]' '[:lower:]')"
echo "host=${host}" >> "$GITHUB_OUTPUT"
echo "image=${image}" >> "$GITHUB_OUTPUT"
- name: Log in to Gitea Container Registry
uses: docker/login-action@v3
with:
registry: ${{ steps.registry.outputs.host }}
username: ${{ gitea.repository_owner }}
password: ${{ secrets.REGISTRY_TOKEN }}
- name: Build and push image
run: |
docker build -t "${{ steps.registry.outputs.host }}/${{ steps.registry.outputs.image }}:latest" .
docker push "${{ steps.registry.outputs.host }}/${{ steps.registry.outputs.image }}:latest"

View File

@ -4,29 +4,22 @@ FROM python:3.9-slim
# Set the working directory
WORKDIR /app
# Install git and clean up
RUN apt-get update -q && \
apt-get install -y git && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Create data directory with proper permissions
RUN mkdir -p /app/data && chmod 755 /app/data
# Set safe directory
RUN git config --global --add safe.directory '*'
# Clone the repository
RUN git init /app && git remote add origin https://git.epicsparrow.com/Anselme/perefouras.git && git fetch --depth 1 origin master && git reset --hard FETCH_HEAD
# Install dependencies
# Install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# give exec permissions to main
RUN chmod +x main.py
# Copy application code
COPY main.py fouras.py rhymes.py database.py ./
COPY resources/ ./resources/
# Create data directory for persistent state
RUN mkdir -p /app/data && chmod 755 /app/data
# Ensure Python output is not buffered (useful for logs)
ENV PYTHONUNBUFFERED=1
# Set data directory as volume mount point
VOLUME /app/data
# Command to update the repo and run the script
CMD ["sh", "-c", "cd /app && git fetch --depth 1 origin master && git reset --hard FETCH_HEAD && python main.py"]
# Run the bot
CMD ["python", "main.py"]

View File

@ -1,11 +1,9 @@
services:
perefouras:
build:
context: .
dockerfile: Dockerfile
image: git.epicsparrow.com/anselme/perefouras:latest
environment:
- DISCORD_TOKEN=${FOURAS_DISCORD_TOKEN}
- MAINTAINER_ID=${FOURAS_MAINTAINER_ID:-151626081458192384}
restart: always
volumes:
- ${FOURAS_DATA_DIR}:/app/data
- ${FOURAS_DATA_DIR}:/app/data