Skip to content

Commit c5ea9ef

Browse files
authored
Merge pull request #3 from launchql/anmol/pgpm-docker
docker: add docker file for pgpm modules
2 parents f87409e + 08221aa commit c5ea9ef

3 files changed

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

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 is the repo root of pgpm-modules)
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)