Skip to content

Commit e0896d7

Browse files
Add a Makefile and update docker files
1 parent 3b8fee2 commit e0896d7

File tree

3 files changed

+91
-6
lines changed

3 files changed

+91
-6
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Docker Publish
2+
3+
on:
4+
push:
5+
branches: [main]
6+
tags: ['v*']
7+
release:
8+
types: [published]
9+
workflow_dispatch:
10+
11+
env:
12+
REGISTRY: ghcr.io
13+
IMAGE_NAME: ${{ github.repository }}
14+
DOCKERFILE: ./Dockerfile
15+
BUILD_CONTEXT: .
16+
17+
jobs:
18+
build-and-push:
19+
runs-on: ubuntu-latest
20+
permissions:
21+
contents: read
22+
packages: write
23+
steps:
24+
- name: Checkout repository
25+
uses: actions/checkout@v4
26+
27+
- name: Set up Docker Buildx
28+
uses: docker/setup-buildx-action@v3
29+
30+
- name: Log in to GitHub Container Registry
31+
uses: docker/login-action@v3
32+
with:
33+
registry: ${{ env.REGISTRY }}
34+
username: ${{ github.actor }}
35+
password: ${{ secrets.GITHUB_TOKEN }}
36+
37+
- name: Extract Docker metadata
38+
id: meta
39+
uses: docker/metadata-action@v5
40+
with:
41+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
42+
tags: |
43+
type=ref,event=branch
44+
type=ref,event=tag
45+
type=sha
46+
type=raw,value=latest,enable={{is_default_branch}}
47+
48+
- name: Build and push image
49+
uses: docker/build-push-action@v6
50+
with:
51+
context: ${{ env.BUILD_CONTEXT }}
52+
file: ${{ env.DOCKERFILE }}
53+
push: true
54+
tags: ${{ steps.meta.outputs.tags }}
55+
labels: ${{ steps.meta.outputs.labels }}

Dockerfile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
# syntax=docker/dockerfile:1.7
22

33
# ---------- Base dependencies ----------
4-
FROM node:20-bookworm-slim AS base
4+
FROM node:22-bookworm-slim AS base
55

66
# set workdir and install common deps
77
WORKDIR /app
8-
ENV NODE_ENV=production
9-
108
RUN apt-get update \
119
&& apt-get install -y --no-install-recommends \
1210
ca-certificates \
@@ -34,16 +32,16 @@ RUN yarn prisma generate \
3432
&& yarn build
3533

3634
# ---------- Production runtime ----------
37-
FROM node:20-bookworm-slim AS runtime
35+
FROM node:22-bookworm-slim AS runtime
3836

3937
WORKDIR /app
4038
ENV NODE_ENV=production
4139
ENV PORT=5000
42-
ENV DATABASE_URL="file:./data/sovereign.db"
40+
ENV DATABASE_URL="file:/app/data/sovereign.db"
4341

4442
# Install tini for proper signal handling
4543
RUN apt-get update \
46-
&& apt-get install -y --no-install-recommends tini \
44+
&& apt-get install -y --no-install-recommends tini openssl \
4745
&& rm -rf /var/lib/apt/lists/*
4846

4947
# Copy production node_modules from deps
@@ -55,6 +53,9 @@ COPY --from=build /app/public ./public
5553
COPY --from=build /app/prisma ./prisma
5654
COPY --from=build /app/package.json ./package.json
5755

56+
# Ensure Prisma client is generated for the runtime environment
57+
RUN yarn prisma generate
58+
5859
# Prepare persistent data directory for sqlite
5960
RUN mkdir -p /app/data \
6061
&& chown node:node /app/data

Makefile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Build the Sovereign Docker image
2+
IMAGE_NAME ?= sovereign
3+
IMAGE_VERSION ?= local
4+
DOCKERFILE ?= Dockerfile
5+
BUILD_CONTEXT ?= .
6+
HOST_PORT ?= 5000
7+
CONTAINER_PORT ?= 5000
8+
DATA_DIR ?= $(CURDIR)/data
9+
ENV_FILE ?= .env
10+
CONTAINER_NAME ?= sovereign
11+
REPLACE_EXISTING ?= false
12+
13+
DOCKER_RUN_ARGS = -d --rm --name $(CONTAINER_NAME) -p $(HOST_PORT):$(CONTAINER_PORT) -v $(DATA_DIR):/app/data
14+
ifneq ($(wildcard $(ENV_FILE)),)
15+
DOCKER_RUN_ARGS += --env-file $(ENV_FILE)
16+
endif
17+
18+
.PHONY: docker-build
19+
docker-build:
20+
@docker build -t $(IMAGE_NAME):$(IMAGE_VERSION) -f $(DOCKERFILE) $(BUILD_CONTEXT)
21+
22+
.PHONY: docker-run
23+
docker-run:
24+
@mkdir -p $(DATA_DIR)
25+
@chmod 777 $(DATA_DIR)
26+
ifeq ($(REPLACE_EXISTING),true)
27+
@docker rm -f $(CONTAINER_NAME) >/dev/null 2>&1 || true
28+
endif
29+
@docker run $(DOCKER_RUN_ARGS) $(IMAGE_NAME):$(IMAGE_VERSION)

0 commit comments

Comments
 (0)