Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Commit

Permalink
feat: add static generation
Browse files Browse the repository at this point in the history
  • Loading branch information
maxgfr committed Jan 28, 2022
1 parent ccb9735 commit b9e062b
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 54 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/deactivate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Deactivate

on:
pull_request:
types: [ closed ]

jobs:
bury_review_env:
name: Deactivate review branch
runs-on: ubuntu-latest
steps:

- uses: SocialGouv/actions/autodevops-deactivate@v1
with:
kube-config: ${{ secrets.KUBECONFIG }}
github-token: ${{ secrets.GITHUB_TOKEN }}
36 changes: 36 additions & 0 deletions .github/workflows/production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Production

on:
push:
tags:
- v*

concurrency:
group: production
cancel-in-progress: true

jobs:

deploy:
name: Deploy production
runs-on: ubuntu-latest
environment:
name: production
url: ${{ steps.autodevops.outputs.url }}
steps:

- name: Get project name
run: |
echo "project=${GITHUB_REPOSITORY#*/}" >> $GITHUB_ENV
- name: Use autodevops to deploy production
uses: SocialGouv/actions/autodevops@v1
id: autodevops
with:
environment: prod
project: ${{ env.project }}
token: ${{ secrets.GITHUB_TOKEN }}
kubeconfig: ${{ secrets.KUBECONFIG }}
imageName: fabrique/${{ env.project }}
rancherId: ${{ secrets.RANCHER_PROJECT_ID }}
socialgouvBaseDomain: ${{ secrets.SOCIALGOUV_BASE_DOMAIN }}
2 changes: 1 addition & 1 deletion .github/workflows/quality.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Code quality

on: [pull_request]
on: [pull_request, push]

concurrency:
cancel-in-progress: true
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Release

on:
workflow_dispatch:
push:
branches: [master, alpha, beta, next]

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:

- uses: SocialGouv/actions/autodevops-release@v1
with:
author-name: ${{ secrets.SOCIALGROOVYBOT_NAME }}
author-email: ${{ secrets.SOCIALGROOVYBOT_EMAIL }}
github-token: ${{ secrets.SOCIALGROOVYBOT_BOTO_PAT }}

34 changes: 34 additions & 0 deletions .github/workflows/review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Review

on:
push:
branches:
- '**'
tags-ignore:
- v*

concurrency:
cancel-in-progress: true
group: review-${{ github.ref }}

jobs:

deploy:
name: Deploy review branch
runs-on: ubuntu-latest
steps:

- name: Get project name
run: |
echo "project=${GITHUB_REPOSITORY#*/}" >> $GITHUB_ENV
- name: Use autodevops to deploy review branch
uses: SocialGouv/actions/autodevops@v1
with:
environment: dev
project: ${{ env.project }}
token: ${{ secrets.GITHUB_TOKEN }}
kubeconfig: ${{ secrets.KUBECONFIG }}
imageName: fabrique/${{ env.project }}
rancherId: ${{ secrets.RANCHER_PROJECT_ID }}
socialgouvBaseDomain: ${{ secrets.SOCIALGOUV_BASE_DOMAIN }}
7 changes: 7 additions & 0 deletions .socialgouv/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "template",
"type": "static",
"subdomain": "template",
"registry": "ghcr",
"project": "fabrique"
}
36 changes: 3 additions & 33 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,15 @@ WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile

# If using npm with a `package-lock.json` comment out above and use below instead
# COPY package.json package-lock.json /
# RUN npm install

# Rebuild the source code only when needed
FROM node:16-alpine AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN yarn build
RUN yarn export

# Production image, copy all the files and run next
FROM node:16-alpine AS runner
WORKDIR /app

ENV NODE_ENV production

RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001

# You only need to copy next.config.js if you are NOT using the default configuration
# COPY --from=builder /app/next.config.js ./
COPY --from=builder /app/public ./public
COPY --from=builder /app/package.json ./package.json

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

USER nextjs

EXPOSE 3000

ENV PORT 3000

# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry.
# ENV NEXT_TELEMETRY_DISABLED 1
FROM ghcr.io/socialgouv/docker/nginx4spa:6.64.2 AS runner

CMD ["node", "server.js"]
COPY --from=builder /app/out /usr/share/nginx/html
5 changes: 1 addition & 4 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
experimental: {
outputStandalone: true,
},
reactStrictMode: true
}

module.exports = nextConfig
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
"lint": "next lint",
"export": "next export"
},
"dependencies": {
"next": "12.0.9",
Expand Down
13 changes: 0 additions & 13 deletions pages/api/hello.ts

This file was deleted.

3 changes: 1 addition & 2 deletions pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { NextPage } from 'next'
import Head from 'next/head'
import Image from 'next/image'
import styles from '../styles/Home.module.css'

const Home: NextPage = () => {
Expand Down Expand Up @@ -61,7 +60,7 @@ const Home: NextPage = () => {
>
Powered by{' '}
<span className={styles.logo}>
<Image src="/vercel.svg" alt="Vercel Logo" width={72} height={16} />
<img src="/vercel.svg" alt="Vercel Logo" width={72} height={16} />
</span>
</a>
</footer>
Expand Down

0 comments on commit b9e062b

Please sign in to comment.