Skip to content

Commit 4f7bccf

Browse files
author
tosaki
committed
feat: Implement Dockerization with Dockerfile, .dockerignore, and a GitHub Actions workflow for image publishing.
1 parent 6594677 commit 4f7bccf

File tree

3 files changed

+166
-0
lines changed

3 files changed

+166
-0
lines changed

.dockerignore

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Git
2+
.git
3+
.gitignore
4+
5+
# Python
6+
__pycache__
7+
*.py[cod]
8+
*$py.class
9+
*.so
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
*.egg-info/
24+
.installed.cfg
25+
*.egg
26+
27+
# Virtual Environment
28+
.venv
29+
venv/
30+
ENV/
31+
env/
32+
33+
# Environment Variables
34+
.env
35+
.env.local
36+
.env.*.local
37+
38+
# IDES
39+
.vscode
40+
.idea
41+
42+
# OS
43+
.DS_Store
44+
Thumbs.db
45+
46+
# Project Specific
47+
dashboard.json
48+
top5.json
49+
news.db
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: Docker
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
# Publish semver tags as releases.
7+
tags: [ 'v*.*.*' ]
8+
pull_request:
9+
branches: [ "main" ]
10+
11+
env:
12+
REGISTRY: ghcr.io
13+
# github.repository as <account>/<repo>
14+
IMAGE_NAME: t0saki/ai-news-dashboard
15+
16+
17+
jobs:
18+
build:
19+
20+
runs-on: ubuntu-latest
21+
permissions:
22+
contents: read
23+
packages: write
24+
# This is used to complete the identity challenge
25+
# with sigstore/fulcio when running outside of PRs.
26+
id-token: write
27+
28+
steps:
29+
- name: Checkout repository
30+
uses: actions/checkout@v3
31+
32+
# Install the cosign tool except on PR
33+
# https://github.com/sigstore/cosign-installer
34+
- name: Install cosign
35+
if: github.event_name != 'pull_request'
36+
uses: sigstore/cosign-installer@v3.5.0
37+
with:
38+
cosign-release: 'v2.2.4'
39+
40+
# Set up BuildKit Docker container builder to be able to build
41+
# multi-platform images and export cache
42+
# https://github.com/docker/setup-buildx-action
43+
- name: Set up Docker Buildx
44+
uses: docker/setup-buildx-action@v3.0.0
45+
46+
# Login against a Docker registry except on PR
47+
# https://github.com/docker/login-action
48+
- name: Log into registry ${{ env.REGISTRY }}
49+
if: github.event_name != 'pull_request'
50+
uses: docker/login-action@v3.0.0
51+
with:
52+
registry: ${{ env.REGISTRY }}
53+
username: ${{ github.actor }}
54+
password: ${{ secrets.GITHUB_TOKEN }}
55+
56+
# Extract metadata (tags, labels) for Docker
57+
# https://github.com/docker/metadata-action
58+
- name: Extract Docker metadata
59+
id: meta
60+
uses: docker/metadata-action@v5.0.0
61+
with:
62+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
63+
tags: type=raw,value=latest,enable={{is_default_branch}}
64+
65+
# Build and push Docker image with Buildx (don't push on PR)
66+
# https://github.com/docker/build-push-action
67+
- name: Build and push Docker image
68+
id: build-and-push
69+
uses: docker/build-push-action@v5.0.0
70+
with:
71+
context: .
72+
push: ${{ github.event_name != 'pull_request' }}
73+
tags: ${{ steps.meta.outputs.tags }}
74+
labels: ${{ steps.meta.outputs.labels }}
75+
cache-from: type=gha
76+
cache-to: type=gha,mode=max
77+
78+
# Sign the resulting Docker image digest except on PRs.
79+
# This will only write to the public Rekor transparency log when the Docker
80+
# repository is public to avoid leaking data. If you would like to publish
81+
# transparency data even for private images, pass --force to cosign below.
82+
# https://github.com/sigstore/cosign
83+
- name: Sign the published Docker image
84+
if: ${{ github.event_name != 'pull_request' }}
85+
env:
86+
TAGS: ${{ steps.meta.outputs.tags }}
87+
DIGEST: ${{ steps.build-and-push.outputs.digest }}
88+
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}

Dockerfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim
2+
3+
# Set working directory
4+
WORKDIR /app
5+
6+
# Enable bytecode compilation
7+
ENV UV_COMPILE_BYTECODE=1
8+
9+
# Copy from the cache instead of linking since it's a mounted volume
10+
ENV UV_LINK_MODE=copy
11+
12+
# Install the project's dependencies using the lockfile and settings
13+
RUN --mount=type=cache,target=/root/.cache/uv \
14+
--mount=type=bind,source=uv.lock,target=uv.lock \
15+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
16+
uv sync --frozen --no-install-project --no-dev
17+
18+
# Place executables in the environment at the front of the path
19+
ENV PATH="/app/.venv/bin:$PATH"
20+
21+
# Copy the rest of the application
22+
COPY . /app
23+
24+
# Sync the project
25+
RUN --mount=type=cache,target=/root/.cache/uv \
26+
uv sync --frozen --no-dev
27+
28+
# Run the application
29+
ENTRYPOINT ["uv", "run", "main.py"]

0 commit comments

Comments
 (0)