Skip to content

Commit 72b5622

Browse files
committed
ci: build and push image to Gitlab registry
1 parent e762cf6 commit 72b5622

3 files changed

Lines changed: 148 additions & 0 deletions

File tree

.dockerignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Node & build artifacts
2+
node_modules
3+
npm-debug.log*
4+
yarn-debug.log*
5+
yarn-error.log*
6+
pnpm-debug.log*
7+
8+
# Output directories
9+
.dist
10+
/build
11+
dist
12+
13+
# VCS & editor
14+
.git
15+
.gitignore
16+
.vscode
17+
.DS_Store
18+
19+
# Prisma generated files can be regenerated
20+
prisma/*.db
21+
22+
# Local env files (provide via secrets at runtime)
23+
.env
24+
.env.*
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Build and Push Docker image to GitLab Registry
2+
3+
on:
4+
workflow_dispatch:
5+
6+
permissions:
7+
contents: read
8+
packages: read
9+
10+
env:
11+
REGISTRY: ${{ vars.GITLAB_REGISTRY || 'registry.gitlab.inria.fr' }}
12+
PROJECT_PATH: ${{ vars.GITLAB_PROJECT_PATH || 'inocs-lab/inocs-sum-odp-frontend' }}
13+
14+
jobs:
15+
docker:
16+
name: Build and Push
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v4
22+
23+
- name: Set up Docker Buildx
24+
uses: docker/setup-buildx-action@v3
25+
26+
- name: Log in to GitLab Container Registry
27+
uses: docker/login-action@v3
28+
with:
29+
registry: ${{ env.REGISTRY }}
30+
username: gitlab-ci-token
31+
password: ${{ secrets.GITLAB_REGISTRY_TOKEN }}
32+
33+
- name: Extract metadata (tags, labels)
34+
id: meta
35+
uses: docker/metadata-action@v5
36+
with:
37+
images: |
38+
${{ env.REGISTRY }}/${{ env.PROJECT_PATH }}
39+
tags: |
40+
type=ref,event=branch
41+
type=ref,event=tag
42+
type=sha,format=short
43+
type=raw,value=latest,enable={{is_default_branch}}
44+
45+
- name: Build and push
46+
uses: docker/build-push-action@v6
47+
with:
48+
context: .
49+
file: ./Dockerfile
50+
push: true
51+
tags: ${{ steps.meta.outputs.tags }}
52+
labels: ${{ steps.meta.outputs.labels }}
53+
54+
- name: Show pushed tags
55+
run: |
56+
echo "Pushed:"
57+
echo "${{ steps.meta.outputs.tags }}" | tr ' ' '\n'

Dockerfile

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# syntax=docker/dockerfile:1.7
2+
3+
# --- Stage 1: Build Astro app -------------------------------------------------
4+
FROM node:20-bookworm-slim AS builder
5+
ENV NODE_ENV=production
6+
7+
# Install minimal utilities (for Prisma + SSL + debugging)
8+
RUN apt-get update && apt-get install -y --no-install-recommends \
9+
ca-certificates openssl \
10+
&& rm -rf /var/lib/apt/lists/*
11+
12+
WORKDIR /app
13+
14+
# Copy dependency files first (better build cache)
15+
COPY package.json package-lock.json ./
16+
17+
# Install full dependencies (including dev for build)
18+
RUN npm ci
19+
20+
# Copy Prisma schema & generate client
21+
COPY prisma ./prisma
22+
RUN npx prisma generate
23+
24+
# Copy source files and build the project
25+
COPY . .
26+
RUN npm run build
27+
28+
# --- Stage 2: Production dependencies only ------------------------------------
29+
FROM node:20-bookworm-slim AS prod-deps
30+
ENV NODE_ENV=production
31+
WORKDIR /app
32+
33+
COPY package.json package-lock.json ./
34+
35+
# Install only production dependencies (omit dev)
36+
RUN npm ci --omit=dev
37+
38+
# Copy Prisma schema and regenerate client (ensures correct runtime client)
39+
COPY prisma ./prisma
40+
RUN npx prisma generate
41+
42+
# --- Stage 3: Final runtime image ---------------------------------------------
43+
FROM node:20-bookworm-slim AS runner
44+
ENV NODE_ENV=production \
45+
HOST=0.0.0.0 \
46+
PORT=4321
47+
48+
WORKDIR /app
49+
50+
# Copy built app & runtime dependencies
51+
COPY --from=builder /app/dist ./dist
52+
COPY --from=prod-deps /app/node_modules ./node_modules
53+
COPY --from=prod-deps /app/prisma ./prisma
54+
COPY package.json ./
55+
56+
# Ensure ownership and drop privileges
57+
RUN chown -R node:node /app
58+
USER node
59+
60+
# Expose Astro Node adapter default port
61+
EXPOSE 4321
62+
63+
# Optional healthcheck for container orchestration
64+
# HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
65+
# CMD node -e "fetch('http://127.0.0.1:'+process.env.PORT).then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"
66+
67+
CMD ["node", "./dist/server/entry.mjs"]

0 commit comments

Comments
 (0)