Skip to content

Commit 2fde023

Browse files
authored
Refactor Docker CI workflow for improved structure
1 parent 9f795a0 commit 2fde023

1 file changed

Lines changed: 47 additions & 59 deletions

File tree

Lines changed: 47 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,47 @@
1-
name: CI - Build and Push to GHCR
2-
3-
on:
4-
release:
5-
types: [published]
6-
workflow_dispatch:
7-
inputs:
8-
force_build:
9-
description: 'Force build and push'
10-
required: false
11-
default: 'false'
12-
type: boolean
13-
14-
env:
15-
REGISTRY: ghcr.io
16-
IMAGE_NAME: ${{ github.repository }}
17-
18-
jobs:
19-
build-and-push-ghcr:
20-
runs-on: ubuntu-latest
21-
permissions:
22-
contents: read
23-
packages: write
24-
25-
steps:
26-
- name: Checkout repository
27-
uses: actions/checkout@v4
28-
29-
- name: Set up Docker Buildx
30-
uses: docker/setup-buildx-action@v3
31-
32-
- name: Log in to GitHub Container Registry
33-
uses: docker/login-action@v3
34-
with:
35-
registry: ${{ env.REGISTRY }}
36-
username: ${{ github.actor }}
37-
password: ${{ secrets.GITHUB_TOKEN }}
38-
39-
- name: Extract metadata (tags, labels)
40-
id: meta
41-
uses: docker/metadata-action@v5
42-
with:
43-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
44-
tags: |
45-
type=semver,pattern={{version}}
46-
type=semver,pattern={{major}}.{{minor}}
47-
type=semver,pattern={{major}}
48-
type=raw,value=latest,enable={{is_default_branch}}
49-
50-
- name: Build and push to GHCR
51-
uses: docker/build-push-action@v5
52-
with:
53-
context: .
54-
platforms: linux/amd64,linux/arm64
55-
push: true
56-
tags: ${{ steps.meta.outputs.tags }}
57-
labels: ${{ steps.meta.outputs.labels }}
58-
cache-from: type=gha
59-
cache-to: type=gha,mode=max
1+
# Start from a Python base image
2+
FROM python:3.10-slim
3+
4+
# Set environment variables
5+
ENV PYTHONDONTWRITEBYTECODE=1
6+
ENV PYTHONUNBUFFERED=1
7+
8+
# Install system dependencies
9+
RUN apt-get update && apt-get install -y \
10+
redis-server \
11+
libmagic1 \
12+
curl \
13+
&& rm -rf /var/lib/apt/lists/*
14+
15+
# Create a non-root user and group
16+
RUN addgroup --system omnipkg && adduser --system --ingroup omnipkg omnipkg
17+
18+
# Set the working directory
19+
WORKDIR /home/omnipkg
20+
21+
# Copy project files (including src/) BEFORE installing
22+
COPY --chown=omnipkg:omnipkg pyproject.toml poetry.lock* ./
23+
COPY --chown=omnipkg:omnipkg src/ ./src/
24+
COPY --chown=omnipkg:omnipkg README.md ./
25+
26+
# Install Python dependencies
27+
RUN pip install --no-cache-dir .
28+
29+
# Copy the entrypoint script
30+
COPY --chown=omnipkg:omnipkg docker-entrypoint.sh ./
31+
RUN chmod +x /home/omnipkg/docker-entrypoint.sh
32+
33+
# Create directories for omnipkg data BEFORE switching user
34+
RUN mkdir -p /home/omnipkg/.omnipkg && \
35+
chown -R omnipkg:omnipkg /home/omnipkg
36+
37+
# NOW switch to non-root user
38+
USER omnipkg
39+
40+
# Expose Redis port (in case external access needed)
41+
EXPOSE 6379
42+
43+
# Expose the application port
44+
EXPOSE 8000
45+
46+
# Specify the entrypoint script
47+
ENTRYPOINT ["/home/omnipkg/docker-entrypoint.sh"]

0 commit comments

Comments
 (0)