From 5f61a4538355a1f901ad534563f29dde90c51978 Mon Sep 17 00:00:00 2001 From: Anselme Date: Thu, 1 Oct 2026 15:36:24 +0200 Subject: [PATCH] Added CI/CD task to automatically build and deploy the docker image --- .gitea/workflows/docker-publish.yaml | 33 ++++++++++++++++++++++++++++ Dockerfile | 33 +++++++++++----------------- docker-compose.yml | 6 ++--- 3 files changed, 48 insertions(+), 24 deletions(-) create mode 100644 .gitea/workflows/docker-publish.yaml diff --git a/.gitea/workflows/docker-publish.yaml b/.gitea/workflows/docker-publish.yaml new file mode 100644 index 0000000..c04c78d --- /dev/null +++ b/.gitea/workflows/docker-publish.yaml @@ -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" diff --git a/Dockerfile b/Dockerfile index 686a8f3..810df53 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] \ No newline at end of file +# Run the bot +CMD ["python", "main.py"] diff --git a/docker-compose.yml b/docker-compose.yml index e328c8f..119cadb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 \ No newline at end of file + - ${FOURAS_DATA_DIR}:/app/data