Skip to content

Commit f0dc11a

Browse files
authored
Merge pull request #24 from ItaloMedici/feature/ci
Feature/ci
2 parents c700ef1 + 60a9beb commit f0dc11a

File tree

9 files changed

+931
-164
lines changed

9 files changed

+931
-164
lines changed

.dockerignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Dockerfile
2+
.dockerignore
3+
docker-compose.yml
4+
node_modules
5+
npm-debug.log
6+
README.md
7+
.next
8+
!.next/static
9+
!.next/standalone
10+
.git

.github/workflows/build-lint-test.yml

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,25 @@ jobs:
77
runs-on: ubuntu-latest
88

99
steps:
10-
- uses: actions/checkout@v4
11-
12-
- name: Use Node.js
13-
uses: actions/setup-node@v3
14-
with:
15-
node-version: 20
16-
cache: 'npm'
17-
18-
- name: Install dependencies
19-
run: npm ci
20-
21-
- name: Run lint
22-
run: npm run lint
23-
24-
- name: Setup Environment
25-
run: cp .env.example .env
26-
27-
- name: Build
28-
run: npm run build --if-present
10+
- uses: actions/checkout@v4
11+
12+
- name: Use Node.js
13+
uses: actions/setup-node@v3
14+
with:
15+
node-version: 20
16+
cache: "npm"
17+
18+
- name: Install dependencies
19+
run: npm ci
20+
21+
- name: Sync db
22+
run: npm run db:generate
23+
24+
- name: Run lint
25+
run: npm run lint
26+
27+
- name: Setup Environment
28+
run: cp .env.example .env
29+
30+
- name: Build
31+
run: npm run build --if-present

.github/workflows/publish-docker.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Create and publish a Docker image
2+
3+
on:
4+
push:
5+
branches: ['release']
6+
workflow_dispatch:
7+
8+
9+
env:
10+
REGISTRY: ghcr.io
11+
IMAGE_NAME: ${{ github.repository }}
12+
13+
jobs:
14+
build-and-push-image:
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
packages: write
19+
attestations: write
20+
id-token: write
21+
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v4
25+
26+
- name: Log in to the Container registry
27+
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
28+
with:
29+
registry: ${{ env.REGISTRY }}
30+
username: ${{ github.actor }}
31+
password: ${{ secrets.GITHUB_TOKEN }}
32+
33+
- name: Extract metadata (tags, labels) for Docker
34+
id: meta
35+
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
36+
with:
37+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
38+
39+
- name: Build and push Docker image
40+
id: push
41+
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
42+
with:
43+
context: .
44+
push: true
45+
tags: ${{ steps.meta.outputs.tags }}
46+
labels: ${{ steps.meta.outputs.labels }}
47+
secrets: |
48+
"NEXTAUTH_URL=${{ secrets.NEXTAUTH_URL }}"
49+
"NEXTAUTH_SECRET=${{ secrets.NEXTAUTH_SECRET }}"
50+
"DATABASE_URL=${{ secrets.DATABASE_URL }}"
51+
"NEXT_PUBLIC_SITE_URL=${{ secrets.NEXT_PUBLIC_SITE_URL }}"
52+
"GOOGLE_CLIENT_ID=${{ secrets.GOOGLE_CLIENT_ID }}"
53+
"GOOGLE_CLIENT_SECRET=${{ secrets.GOOGLE_CLIENT_SECRET }}"
54+
"MAXIMUM_PLAYERS_PER_BOARD=${{ secrets.MAXIMUM_PLAYERS_PER_BOARD }}"
55+
56+
- name: Generate artifact attestation
57+
uses: actions/attest-build-provenance@v1
58+
with:
59+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
60+
subject-digest: ${{ steps.push.outputs.digest }}
61+
push-to-registry: true
62+

.github/workflows/release-it.yml

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,28 @@ name: Release It
22

33
on: workflow_dispatch
44

5-
jobs:
5+
jobs:
66
release:
77
runs-on: ubuntu-latest
88

99
steps:
10-
- uses: actions/checkout@v4
11-
with:
12-
fetch-depth: 0
10+
- uses: actions/checkout@v4
11+
with:
12+
fetch-depth: 0
1313

14-
- name: Use Node.js
15-
uses: actions/setup-node@v3
16-
with:
17-
node-version: 20
18-
cache: 'npm'
14+
- name: Use Node.js
15+
uses: actions/setup-node@v3
16+
with:
17+
node-version: 20
18+
cache: "npm"
1919

20-
- name: git config
21-
run: |
22-
git config user.name "${GITHUB_ACTOR}"
23-
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
24-
25-
- name: Release
26-
run: npm install --global release-it @release-it/conventional-changelog && release-it
20+
- name: git config
21+
run: |
22+
git config user.name "${GITHUB_ACTOR}"
23+
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
2724
28-
env:
29-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25+
- name: Release
26+
run: npm install --global release-it @release-it/conventional-changelog && release-it
27+
28+
env:
29+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Dockerfile

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
FROM --platform=linux/amd64 node:18-alpine AS base
2+
3+
# Install dependencies only when needed
4+
FROM base AS deps
5+
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
6+
RUN apk add --no-cache libc6-compat
7+
WORKDIR /app
8+
9+
# Install dependencies based on the preferred package manager
10+
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
11+
RUN \
12+
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
13+
elif [ -f package-lock.json ]; then npm ci; \
14+
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
15+
else echo "Lockfile not found." && exit 1; \
16+
fi
17+
18+
19+
# Rebuild the source code only when needed
20+
FROM base AS builder
21+
WORKDIR /app
22+
COPY --from=deps /app/node_modules ./node_modules
23+
COPY . .
24+
25+
RUN --mount=type=secret,id=NEXTAUTH_URL \
26+
sed -i "s/NEXTAUTH_URL=/NEXTAUTH_URL=$(cat /run/secrets/NEXTAUTH_URL)/" .env
27+
28+
RUN --mount=type=secret,id=NEXTAUTH_SECRET \
29+
sed -i "s/NEXTAUTH_SECRET=/NEXTAUTH_SECRET=$(cat /run/secrets/NEXTAUTH_SECRET)/" .env
30+
31+
RUN --mount=type=secret,id=DATABASE_URL \
32+
sed -i "s/DATABASE_URL=/DATABASE_URL=$(cat /run/secrets/DATABASE_URL)/" .env
33+
34+
RUN --mount=type=secret,id=NEXT_PUBLIC_SITE_URL \
35+
sed -i "s/NEXT_PUBLIC_SITE_URL=/NEXT_PUBLIC_SITE_URL=$(cat /run/secrets/NEXT_PUBLIC_SITE_URL)/" .env
36+
37+
RUN --mount=type=secret,id=GOOGLE_CLIENT_ID \
38+
sed -i "s/GOOGLE_CLIENT_ID=/GOOGLE_CLIENT_ID=$(cat /run/secrets/GOOGLE_CLIENT_ID)/" .env
39+
40+
RUN --mount=type=secret,id=GOOGLE_CLIENT_SECRET \
41+
sed -i "s/GOOGLE_CLIENT_SECRET=/GOOGLE_CLIENT_SECRET=$(cat /run/secrets/GOOGLE_CLIENT_SECRET)/" .env
42+
43+
RUN --mount=type=secret,id=MAXIMUM_PLAYERS_PER_BOARD \
44+
sed -i "s/MAXIMUM_PLAYERS_PER_BOARD=/MAXIMUM_PLAYERS_PER_BOARD=$(cat /run/secrets/MAXIMUM_PLAYERS_PER_BOARD)/" .env
45+
46+
RUN npm run db:generate
47+
48+
RUN npm run build
49+
50+
FROM base AS runner
51+
WORKDIR /app
52+
53+
ENV NODE_ENV=production
54+
55+
RUN addgroup --system --gid 1001 nodejs
56+
RUN adduser --system --uid 1001 nextjs
57+
58+
COPY --from=builder /app/public ./public
59+
60+
# Set the correct permission for prerender cache
61+
RUN mkdir .next
62+
RUN chown nextjs:nodejs .next
63+
64+
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
65+
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
66+
67+
USER nextjs
68+
69+
EXPOSE 3000
70+
71+
ENV PORT=3000
72+
73+
ENV HOSTNAME="0.0.0.0"
74+
CMD ["node", "server.js"]

next.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/** @type {import('next').NextConfig} */
22
const nextConfig = {
3+
output: "standalone",
34
images: {
45
remotePatterns: [
56
{

0 commit comments

Comments
 (0)