Skip to content

Commit e09d7bc

Browse files
committed
add docker file for pgpm modules
1 parent f87409e commit e09d7bc

3 files changed

Lines changed: 158 additions & 0 deletions

File tree

.dockerignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
node_modules
2+
**/node_modules
3+
**/dist
4+
**/.DS_Store
5+
.git
6+
.gitignore
7+
.github
8+
npm-debug.log
9+
pnpm-debug.log
10+
yarn-error.log
11+
Dockerfile*
12+

.github/workflows/docker.yaml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Docker
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- '.github/workflows/docker.yaml'
9+
pull_request:
10+
branches:
11+
- main
12+
workflow_dispatch: {}
13+
14+
permissions:
15+
contents: read
16+
packages: write
17+
18+
concurrency:
19+
group: docker-pgpm-modules-${{ github.ref }}
20+
cancel-in-progress: true
21+
22+
env:
23+
IMAGE_NAME: pgpm/modules
24+
IMAGE_REGISTRY: ghcr.io
25+
IMAGE_REPO: ${{ github.repository_owner }}
26+
BUILD_CONTEXT: pgpm-modules
27+
DOCKERFILE_PATH: pgpm-modules/Dockerfile
28+
PLATFORMS: ${{ github.event_name != 'pull_request' && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
29+
30+
jobs:
31+
build-and-push:
32+
runs-on: ubuntu-latest
33+
steps:
34+
- name: Checkout
35+
uses: actions/checkout@v4
36+
37+
- name: Set up QEMU (enable arm64 emulation)
38+
uses: docker/setup-qemu-action@v3
39+
40+
- name: Set up Docker Buildx
41+
uses: docker/setup-buildx-action@v3
42+
43+
- name: Login to GHCR
44+
if: github.event_name != 'pull_request'
45+
uses: docker/login-action@v3
46+
with:
47+
registry: ghcr.io
48+
username: ${{ github.actor }}
49+
password: ${{ secrets.GITHUB_TOKEN }}
50+
51+
- name: Extract Docker metadata
52+
id: meta
53+
uses: docker/metadata-action@v5
54+
with:
55+
images: |
56+
${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_REPO }}/${{ env.IMAGE_NAME }}
57+
tags: |
58+
type=sha,format=short,prefix=
59+
type=ref,event=branch
60+
type=ref,event=pr
61+
type=raw,value=latest,enable={{is_default_branch}}
62+
63+
- name: Build and push
64+
uses: docker/build-push-action@v6
65+
with:
66+
context: ${{ env.BUILD_CONTEXT }}
67+
file: ${{ env.DOCKERFILE_PATH }}
68+
push: ${{ github.event_name != 'pull_request' }}
69+
platforms: ${{ env.PLATFORMS }}
70+
tags: ${{ steps.meta.outputs.tags }}
71+
labels: ${{ steps.meta.outputs.labels }}
72+
cache-from: type=gha
73+
cache-to: type=gha,mode=max
74+
75+
- name: Image digest
76+
run: echo "Pushed ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_REPO }}/${{ env.IMAGE_NAME }} with tags - ${{ steps.meta.outputs.tags }}"
77+

Dockerfile

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
ARG BASE=node
2+
ARG BASE_VERSION=20-bookworm
3+
FROM ${BASE}:${BASE_VERSION} AS build
4+
5+
LABEL org.opencontainers.image.source="https://github.com/launchql/pgpm-modules"
6+
ARG BASE
7+
ARG BASE_VERSION
8+
ENV BASE_VERSION=${BASE_VERSION}
9+
10+
WORKDIR /app
11+
12+
# System deps and pnpm (match workspace requirement)
13+
RUN set -eux; \
14+
apt-get update; \
15+
apt-get install -y --no-install-recommends ca-certificates curl git; \
16+
update-ca-certificates || true; \
17+
corepack enable; \
18+
corepack prepare pnpm@10.12.2 --activate; \
19+
rm -rf /var/lib/apt/lists/*
20+
21+
# Copy workspace (build context should be pgpm-modules directory)
22+
COPY . .
23+
24+
# Install workspace deps and bundle packages
25+
RUN set -eux; \
26+
pnpm install --frozen-lockfile; \
27+
pnpm -r bundle
28+
29+
# Collect packaged SQL and relevant metadata into /out
30+
RUN set -eux; \
31+
mkdir -p /out; \
32+
for p in /app/packages/*; do \
33+
name="$(basename "$p")"; \
34+
dest="/out/${name}"; \
35+
mkdir -p "$dest"; \
36+
# copy packaged SQL if present
37+
if [ -d "$p/sql" ]; then \
38+
mkdir -p "$dest/sql"; \
39+
cp -R "$p/sql"/* "$dest/sql/" || true; \
40+
fi; \
41+
# copy plan for reference (optional at runtime)
42+
if [ -f "$p/pgpm.plan" ]; then \
43+
cp "$p/pgpm.plan" "$dest/"; \
44+
fi; \
45+
# include package.json for provenance/versioning
46+
if [ -f "$p/package.json" ]; then \
47+
cp "$p/package.json" "$dest/"; \
48+
fi; \
49+
done
50+
51+
################################################################################
52+
FROM debian:bookworm-slim AS runtime
53+
54+
LABEL org.opencontainers.image.source="https://github.com/launchql/pgpm-modules"
55+
WORKDIR /pgpm
56+
57+
# Minimal runtime with CA certs for potential HTTPS fetches
58+
RUN set -eux; \
59+
apt-get update; \
60+
apt-get install -y --no-install-recommends ca-certificates; \
61+
update-ca-certificates || true; \
62+
rm -rf /var/lib/apt/lists/*
63+
64+
COPY --from=build /out /pgpm/packages
65+
66+
ENV PGPM_MODULES_DIR=/pgpm/packages
67+
68+
# Default command: list packaged modules
69+
CMD ["sh", "-lc", "ls -1 ${PGPM_MODULES_DIR} || true"]

0 commit comments

Comments
 (0)