Skip to content

Commit f653dd1

Browse files
committed
Add Docker support for Go version - Add multi-stage Dockerfile with minimal base image - Create docker-compose.yml with different profiles - Add .dockerignore to optimize build - Create Docker usage guide
1 parent 6c2c76e commit f653dd1

File tree

4 files changed

+336
-133
lines changed

4 files changed

+336
-133
lines changed

.dockerignore

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,57 @@
1-
.git
1+
# Git and GitHub
2+
.git/
3+
.github/
24
.gitignore
3-
.DS_Store
5+
6+
# Development and CI files
7+
.vscode/
8+
.idea/
9+
*.swp
10+
*.swo
11+
.env
12+
.env.example
13+
docker-compose*.yml
14+
.dockerignore
15+
*.md
16+
!README.md
17+
!LICENSE
18+
19+
# Build artifacts
20+
bin/
21+
coverage*
22+
*.out
23+
*.test
24+
*.prof
25+
__debug_bin*
26+
tmp/
27+
28+
# Generated data
29+
exports/
430
logs/
31+
config/
32+
*.csv
33+
*.json
34+
35+
# Node.js files (for old version)
36+
node_modules/
37+
npm-debug.log
38+
39+
# Go specific
40+
vendor/
41+
dist/
42+
43+
# Test directories
44+
tests/
45+
46+
# Documentation
47+
docs/
48+
49+
.DS_Store
550
backup/
651
copy/
752
brain_ops/
853
TEMP/
954
*.tar.gz
1055
letterboxd_import.csv
1156
watched_*.csv
12-
watchlist_*.csv
13-
README.md
14-
LICENSE
57+
watchlist_*.csv

Dockerfile

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,35 @@
22
FROM golang:1.22-alpine AS builder
33

44
# Install build dependencies
5-
RUN apk add --no-cache git
5+
RUN apk add --no-cache git gcc musl-dev
6+
7+
# Set build arguments
8+
ARG VERSION=dev
9+
ARG COMMIT_SHA=unknown
10+
ARG BUILD_DATE=unknown
611

712
# Set working directory
813
WORKDIR /app
914

10-
# Copy go mod files
11-
COPY go.mod ./
12-
13-
# Download dependencies
15+
# Copy go module files
16+
COPY go.mod go.sum ./
1417
RUN go mod download
1518

1619
# Copy source code
1720
COPY . .
1821

19-
# Build the application
20-
RUN CGO_ENABLED=0 GOOS=linux go build -o export_trakt ./cmd/export_trakt
22+
# Build binary with version information
23+
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo \
24+
-ldflags "-s -w \
25+
-X github.com/JohanDevl/Export_Trakt_4_Letterboxd/pkg/version.Version=${VERSION} \
26+
-X github.com/JohanDevl/Export_Trakt_4_Letterboxd/pkg/version.CommitSHA=${COMMIT_SHA} \
27+
-X github.com/JohanDevl/Export_Trakt_4_Letterboxd/pkg/version.BuildDate=${BUILD_DATE}" \
28+
-o export-trakt ./cmd/export_trakt
2129

22-
# Final stage
30+
# Runtime stage
2331
FROM alpine:3.19
2432

25-
# Install runtime dependencies
33+
# Install CA certificates for HTTPS
2634
RUN apk add --no-cache ca-certificates tzdata
2735

2836
# Create non-root user
@@ -31,25 +39,39 @@ RUN addgroup -S appgroup && adduser -S appuser -G appgroup
3139
# Set working directory
3240
WORKDIR /app
3341

34-
# Copy binary from builder
35-
COPY --from=builder /app/export_trakt .
42+
# Create directories and set permissions
43+
RUN mkdir -p /app/config /app/logs /app/exports \
44+
&& chown -R appuser:appgroup /app
3645

37-
# Copy configuration
38-
COPY config/config.toml /app/config/
46+
# Copy binary from builder stage
47+
COPY --from=builder /app/export-trakt /app/export-trakt
3948

40-
# Create necessary directories
41-
RUN mkdir -p /app/exports /app/logs \
42-
&& chown -R appuser:appgroup /app
49+
# Copy locales
50+
COPY --from=builder /app/locales /app/locales
4351

4452
# Set environment variables
45-
ENV CONFIG_PATH=/app/config/config.toml \
46-
TZ=UTC
53+
ENV EXPORT_TRAKT_EXPORT_OUTPUT_DIR=/app/exports
54+
ENV EXPORT_TRAKT_LOGGING_FILE=/app/logs/export.log
4755

4856
# Switch to non-root user
4957
USER appuser
5058

51-
# Set volume for persistent data
52-
VOLUME ["/app/exports", "/app/logs"]
59+
# Create volumes for persistent data
60+
VOLUME ["/app/config", "/app/logs", "/app/exports"]
5361

5462
# Set entrypoint
55-
ENTRYPOINT ["/app/export_trakt"]
63+
ENTRYPOINT ["/app/export-trakt"]
64+
65+
# Default command if none is provided
66+
CMD ["--help"]
67+
68+
# Metadata
69+
LABEL org.opencontainers.image.title="Export Trakt for Letterboxd"
70+
LABEL org.opencontainers.image.description="Tool to export Trakt.tv data for Letterboxd import"
71+
LABEL org.opencontainers.image.authors="JohanDevl"
72+
LABEL org.opencontainers.image.url="https://github.com/JohanDevl/Export_Trakt_4_Letterboxd"
73+
LABEL org.opencontainers.image.source="https://github.com/JohanDevl/Export_Trakt_4_Letterboxd"
74+
LABEL org.opencontainers.image.version="${VERSION}"
75+
LABEL org.opencontainers.image.created="${BUILD_DATE}"
76+
LABEL org.opencontainers.image.revision="${COMMIT_SHA}"
77+
LABEL org.opencontainers.image.licenses="MIT"

docker-compose.yml

Lines changed: 73 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,124 +1,90 @@
11
version: "3.8"
22

33
services:
4-
# Default service - runs once and exits
5-
trakt-export:
6-
build:
7-
context: .
8-
args:
9-
- APP_VERSION=dev
10-
- BUILD_DATE=${BUILD_DATE:-unknown}
11-
- VCS_REF=${VCS_REF:-unknown}
12-
container_name: trakt-export
4+
# Base service configuration (not started directly)
5+
export-trakt-base: &export-trakt-base
6+
image: johandevl/export-trakt-4-letterboxd:latest
7+
container_name: export-trakt
138
volumes:
149
- ./config:/app/config
1510
- ./logs:/app/logs
16-
- ./copy:/app/copy
17-
- ./backup:/app/backup
18-
environment:
19-
- TZ=Europe/Paris
20-
# Leave CRON_SCHEDULE empty to run once and exit
21-
- EXPORT_OPTION=complete
11+
- ./exports:/app/exports
2212
restart: "no"
23-
stdin_open: true
13+
environment:
14+
- TZ=UTC
15+
16+
# Normal export (default)
17+
export-trakt:
18+
<<: *export-trakt-base
19+
profiles: ["default", "export"]
20+
command: ["export", "--mode", "normal"]
21+
22+
# Interactive setup
23+
export-trakt-setup:
24+
<<: *export-trakt-base
25+
profiles: ["setup"]
26+
command: ["setup"]
27+
# Interactive TTY for setup process
2428
tty: true
25-
healthcheck:
26-
test: ["CMD", "/app/docker-entrypoint.sh", "healthcheck"]
27-
interval: 30s
28-
timeout: 10s
29-
retries: 3
30-
start_period: 5s
29+
stdin_open: true
3130

32-
# Service that runs on a schedule using cron
33-
trakt-export-scheduled:
34-
profiles: ["scheduled"]
35-
build:
36-
context: .
37-
args:
38-
- APP_VERSION=dev
39-
container_name: trakt-export-scheduled
40-
volumes:
41-
- ./config:/app/config
42-
- ./logs:/app/logs
43-
- ./copy:/app/copy
44-
- ./backup:/app/backup
45-
environment:
46-
- TZ=Europe/Paris
47-
- CRON_SCHEDULE=* * * * *
48-
- EXPORT_OPTION=complete
49-
restart: unless-stopped
50-
healthcheck:
51-
test: ["CMD", "/app/docker-entrypoint.sh", "healthcheck"]
52-
interval: 1m
53-
timeout: 10s
54-
retries: 3
55-
start_period: 30s
31+
# Complete export
32+
export-trakt-complete:
33+
<<: *export-trakt-base
34+
profiles: ["complete"]
35+
command: ["export", "--mode", "complete"]
5636

57-
# Service that runs on a schedule using cron
58-
trakt-export-scheduled-repo:
59-
#image: ghcr.io/johandevl/export_trakt_4_letterboxd:pr-29
60-
build:
61-
context: .
62-
args:
63-
- APP_VERSION=dev
64-
container_name: trakt-export-scheduled-repo
65-
volumes:
66-
- ./config:/app/config
67-
- ./logs:/app/logs
68-
- ./copy:/app/copy
69-
- ./backup:/app/backup
70-
environment:
71-
- TZ=Europe/Paris
72-
# Run every day at 3 AM
73-
- CRON_SCHEDULE=* * * * *
74-
- EXPORT_OPTION=normal
75-
restart: unless-stopped
76-
healthcheck:
77-
test: ["CMD", "/app/docker-entrypoint.sh", "healthcheck"]
78-
interval: 1m
79-
timeout: 10s
80-
retries: 3
81-
start_period: 30s
37+
# Initial export
38+
export-trakt-initial:
39+
<<: *export-trakt-base
40+
profiles: ["initial"]
41+
command: ["export", "--mode", "initial"]
42+
43+
# Validate configuration
44+
export-trakt-validate:
45+
<<: *export-trakt-base
46+
profiles: ["validate"]
47+
command: ["validate"]
8248

83-
# Example with all configuration passed via environment variables
84-
trakt-export-env:
85-
profiles: ["env-config"]
49+
# Scheduled export (runs as cron job)
50+
export-trakt-scheduled:
51+
<<: *export-trakt-base
52+
profiles: ["scheduled"]
8653
image: johandevl/export-trakt-4-letterboxd:latest
87-
container_name: trakt-export-env
88-
volumes:
89-
- trakt_logs:/app/logs
90-
- trakt_copy:/app/copy
91-
- trakt_backup:/app/backup
92-
environment:
93-
- TZ=Europe/Paris
94-
# API configuration - replace with your actual values
95-
- TRAKT_API_KEY=${TRAKT_API_KEY}
96-
- TRAKT_API_SECRET=${TRAKT_API_SECRET}
97-
- TRAKT_ACCESS_TOKEN=${TRAKT_ACCESS_TOKEN}
98-
- TRAKT_REFRESH_TOKEN=${TRAKT_REFRESH_TOKEN}
99-
- TRAKT_USERNAME=${TRAKT_USERNAME}
100-
# Schedule and export options
101-
- CRON_SCHEDULE=0 3 * * *
102-
- EXPORT_OPTION=normal
10354
restart: unless-stopped
104-
healthcheck:
105-
test: ["CMD", "/app/docker-entrypoint.sh", "healthcheck"]
106-
interval: 1m
107-
timeout: 10s
108-
retries: 3
109-
110-
# Setup command - use this to run the initial setup
111-
trakt-setup:
112-
profiles: ["setup"]
113-
build: .
114-
container_name: trakt-setup
115-
volumes:
116-
- ./config:/app/config
55+
# This entrypoint overrides the default to run as a cron job
56+
entrypoint: ["/bin/sh", "-c"]
57+
# Run every day at 2 AM
58+
command: >
59+
"
60+
echo \"$$EXPORT_SCHEDULE\" > /tmp/crontab &&
61+
echo \"# Run Export Trakt for Letterboxd\" >> /tmp/crontab &&
62+
echo \"$$EXPORT_SCHEDULE /app/export-trakt export >> /app/logs/cron.log 2>&1\" >> /tmp/crontab &&
63+
crond -f -d 8 -c /tmp
64+
"
11765
environment:
118-
- TZ=Europe/Paris
119-
entrypoint: ["/app/docker-entrypoint.sh", "setup"]
120-
stdin_open: true # Needed for interactive prompts
121-
tty: true # Needed for interactive prompts
66+
- TZ=UTC
67+
- EXPORT_SCHEDULE=0 2 * * * # Run every day at 2 AM
68+
69+
# Docker Compose usage examples:
70+
#
71+
# Default export (normal mode):
72+
# docker-compose up
73+
#
74+
# Interactive setup:
75+
# docker-compose --profile setup up
76+
#
77+
# Complete export:
78+
# docker-compose --profile complete up
79+
#
80+
# Initial export:
81+
# docker-compose --profile initial up
82+
#
83+
# Validate configuration:
84+
# docker-compose --profile validate up
85+
#
86+
# Scheduled export (runs as cron job):
87+
# docker-compose --profile scheduled up -d
12288

12389
volumes:
12490
trakt_logs:

0 commit comments

Comments
 (0)