Added CI/CD task to automatically build and deploy the docker image
This commit is contained in:
parent
d955a7a801
commit
5f61a45383
33
.gitea/workflows/docker-publish.yaml
Normal file
33
.gitea/workflows/docker-publish.yaml
Normal 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"
|
||||||
33
Dockerfile
33
Dockerfile
@ -4,29 +4,22 @@ FROM python:3.9-slim
|
|||||||
# Set the working directory
|
# Set the working directory
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Install git and clean up
|
# Install Python dependencies
|
||||||
RUN apt-get update -q && \
|
COPY requirements.txt .
|
||||||
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
|
|
||||||
RUN pip install --no-cache-dir -r requirements.txt
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
# give exec permissions to main
|
# Copy application code
|
||||||
RUN chmod +x main.py
|
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
|
# Set data directory as volume mount point
|
||||||
VOLUME /app/data
|
VOLUME /app/data
|
||||||
|
|
||||||
# Command to update the repo and run the script
|
# Run the bot
|
||||||
CMD ["sh", "-c", "cd /app && git fetch --depth 1 origin master && git reset --hard FETCH_HEAD && python main.py"]
|
CMD ["python", "main.py"]
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
services:
|
services:
|
||||||
perefouras:
|
perefouras:
|
||||||
build:
|
image: git.epicsparrow.com/anselme/perefouras:latest
|
||||||
context: .
|
|
||||||
dockerfile: Dockerfile
|
|
||||||
environment:
|
environment:
|
||||||
- DISCORD_TOKEN=${FOURAS_DISCORD_TOKEN}
|
- DISCORD_TOKEN=${FOURAS_DISCORD_TOKEN}
|
||||||
- MAINTAINER_ID=${FOURAS_MAINTAINER_ID:-151626081458192384}
|
- MAINTAINER_ID=${FOURAS_MAINTAINER_ID:-151626081458192384}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user