Skip to content

Commit b9fa957

Browse files
authored
Add image build flow (#13)
* add docker image creation * update image build to alpine python * add labels
1 parent b002d21 commit b9fa957

File tree

3 files changed

+73
-9
lines changed

3 files changed

+73
-9
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Docker Build and Publish
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
tags: [ 'v*.*.*' ]
7+
pull_request:
8+
branches: [ "main" ]
9+
10+
env:
11+
REGISTRY: ghcr.io
12+
IMAGE_NAME: ${{ github.repository }}
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
19+
packages: write
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
25+
- name: Log in to the Container registry
26+
uses: docker/login-action@v3
27+
with:
28+
registry: ${{ env.REGISTRY }}
29+
username: ${{ github.actor }}
30+
password: ${{ secrets.GITHUB_TOKEN }}
31+
32+
- name: Extract metadata (tags, labels) for Docker
33+
id: meta
34+
uses: docker/metadata-action@v5
35+
with:
36+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
37+
tags: |
38+
type=ref,event=branch
39+
type=ref,event=pr
40+
type=semver,pattern={{version}}
41+
type=semver,pattern={{major}}.{{minor}}
42+
type=sha
43+
44+
- name: Build and push Docker image
45+
uses: docker/build-push-action@v5
46+
with:
47+
context: .
48+
push: ${{ github.event_name != 'pull_request' }}
49+
tags: ${{ steps.meta.outputs.tags }}
50+
labels: ${{ steps.meta.outputs.labels }}

Dockerfile

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,40 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
2020
&& rm -rf /var/lib/apt/lists/* \
2121
&& apt-get clean
2222

23-
# Install Python dependencies
23+
# Copy requirements first to leverage Docker cache
2424
COPY requirements.txt .
2525
RUN pip install --no-cache-dir -r requirements.txt
2626

27-
# Copy project files
28-
COPY . .
29-
30-
# Install the package in development mode
31-
RUN pip install -e .
32-
3327
# Create necessary directories with proper permissions
3428
RUN mkdir -p /app/src/bluesky_notify/data /app/logs /app/instance \
3529
&& chmod -R 777 /app/src/bluesky_notify/data \
3630
&& chmod -R 777 /app/logs \
3731
&& chmod 777 /app/instance
3832

39-
# Create a non-root user and set ownership
33+
# Create a non-root user
4034
RUN useradd -m -r appuser \
4135
&& chown -R appuser:appuser /app
4236

37+
# Copy project files
38+
COPY --chown=appuser:appuser . .
39+
40+
# Install the package
41+
RUN pip install --no-cache-dir .
42+
43+
# Switch to non-root user
4344
USER appuser
4445

46+
# Expose the application port
47+
EXPOSE 5001
48+
4549
# Health check
4650
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
4751
CMD python -c "import requests; requests.get('http://localhost:5001/health')"
4852

4953
# Run the application
5054
CMD ["python", "run.py"]
55+
56+
# Set labels
57+
LABEL org.opencontainers.image.source="https://github.com/jerdog/bluesky-notify"
58+
LABEL org.opencontainers.image.description="A cross-platform notification system for tracking and receiving alerts about new Bluesky social media posts."
59+
LABEL org.opencontainers.image.licenses="MIT"

run.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727

2828
# Start the application
2929
logger.info("Starting Bluesky Notification Tracker...")
30-
app.run(host="0.0.0.0", port=port, debug=True)
30+
is_container = os.environ.get('DOCKER_CONTAINER', 'false').lower() == 'true'
31+
app.run(
32+
host="0.0.0.0",
33+
port=port,
34+
debug=not is_container # Disable debug mode in container
35+
)
3136
except Exception as e:
3237
logger.error(f"Application failed to start: {str(e)}")

0 commit comments

Comments
 (0)