Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node 18, Nuxt 2.17, npm, update deps #3

Merged
merged 5 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/node_modules
/dist
/.nuxt
/doc-dist
/nuxt-dist
/data
/types
65 changes: 30 additions & 35 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,40 @@ on:
push:
branches: [ '*' ]
tags: [ 'v*.*.*' ]
pull_request:

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- run: echo $GITHUB_REF
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- uses: c-hive/gha-yarn-cache@v2
- name: Checkout git repository
uses: actions/checkout@v3

- run: yarn
- run: yarn run lint
- run: NO_UI=true docker-compose up -d
- name: Wait for containers
uses: jakejarvis/wait-action@master
with:
time: '15s'
- run: docker ps
- run: yarn test
- run: docker-compose stop
# no need to work on a cache here, it is not faster than pulling
# instead work on moving to some images hosted on ghcr.io, it is the fastest
- name: Run test dependencies
run: |
docker compose pull --quiet
NO_UI=true docker compose up -d --wait

- name: Docker meta
- name: Prepare docker image tags
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository }}
tag-semver: |
{{version}}
{{major}}.{{minor}}
{{major}}
images: ghcr.io/${{ github.repository }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}

- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v2
with:
driver-opts: network=host

- name: Login to Github container registry
uses: docker/login-action@v1
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
Expand All @@ -62,21 +50,28 @@ jobs:

- name: Build and push docker images
id: docker_build
uses: docker/build-push-action@v2
uses: docker/build-push-action@v3
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
allow: network.host
network: host
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Stop test dependencies
run: docker compose stop

- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}

- name: Send Keel notification to staging-koumoul.com
if: startsWith(github.ref, 'refs/heads/')
run: |
curl -s --fail --show-error -X POST https://keel.admin.staging-koumoul.com/v1/webhooks/native -u ${{ secrets.KEEL_STAGING_USER }}:${{ secrets.KEEL_STAGING_PASSWORD }} -d '{"name": "ghcr.io/${{ github.repository }}", "tag": "${{ steps.docker_meta.outputs.version }}"}'
- name: Send Keel notification to koumoul.com
if: startsWith(github.ref, 'refs/tags/v')
run: |
curl -s --fail --show-error -X POST https://keel.admin.koumoul.com/v1/webhooks/native -u ${{ secrets.KEEL_PROD_USER }}:${{ secrets.KEEL_PROD_PASSWORD }} -d '{"name": "ghcr.io/${{ github.repository }}", "tag": "${{ steps.docker_meta.outputs.version }}"}'
curl -s --fail --show-error -X POST https://keel.admin.koumoul.com/v1/webhooks/native -u ${{ secrets.KEEL_PROD_USER }}:${{ secrets.KEEL_PROD_PASSWORD }} -d '{"name": "ghcr.io/${{ github.repository }}", "tag": "${{ steps.docker_meta.outputs.version }}"}'
13 changes: 0 additions & 13 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,5 @@
/config/local-*
.idea/

# using yarn is recommended
package-lock.json

# yarn without using zero-installs mode
# cf https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

public/assets/css/
public/assets/fonts/
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v16.3.0
18
768 changes: 0 additions & 768 deletions .yarn/releases/yarn-3.1.0.cjs

This file was deleted.

2 changes: 0 additions & 2 deletions .yarnrc.yml

This file was deleted.

82 changes: 62 additions & 20 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,32 +1,74 @@
FROM node:16.13.0-alpine3.13
############################################################################################################
# Stage: prepare a base image with all native utils pre-installed, used both by builder and definitive image
FROM node:18.18.2-alpine3.18 AS nativedeps
RUN apk add --no-cache curl
######################################
FROM nativedeps AS builder
MAINTAINER "contact@koumoul.com"

ENV NODE_ENV production
WORKDIR /webapp
# Installing clean-modules
RUN npm install --location=global clean-modules@3.0.4

RUN apk add --no-cache curl
WORKDIR /webapp

# Installing dependencies in webapp directory
ADD LICENSE .
ADD .yarnrc.yml .
ADD package.json .
ADD yarn.lock .
# adding yarn cache takes a bit of space but speeds up build, remove this line to inverse the trade-off
# in following versions of the stack we will use the yarn pnp option to prevent creating the node_modules directory
ADD .yarn .yarn
RUN yarn
ADD nodemon.json .
COPY LICENSE .
COPY package.json .
COPY package-lock.json .

RUN npm ci && clean-modules --yes "!**/*.eslintrc.json" "!*mocha/lib/test.js" "!**/*.mustache"

# Adding UI files
ADD public public
ADD nuxt.config.js .
ADD config config
ADD contract contract
RUN yarn run build
COPY public public
COPY nuxt.config.js .
COPY config config
COPY contract contract

# Build UI
ENV NODE_ENV production
RUN npm run build

# Adding server files
ADD server server
ADD README.md BUILD.json* ./
COPY server server

# Check quality
COPY .eslintignore .eslintignore
COPY .gitignore .gitignore
RUN npm run lint
COPY test test
RUN npm run test
RUN npm audit --omit=dev --audit-level=critical

# Cleanup /webapp/node_modules so it can be copied by next stage
RUN npm prune --production
RUN rm -rf node_modules/.cache

##################################
# Stage: main nodejs service stage
FROM nativedeps
MAINTAINER "contact@koumoul.com"

RUN apk add --no-cache dumb-init

WORKDIR /webapp

# We could copy /webapp whole, but this is better for layering / efficient cache use
COPY --from=builder /webapp/node_modules /webapp/node_modules
COPY --from=builder /webapp/package.json /webapp/package.json
COPY --from=builder /webapp/nuxt-dist /webapp/nuxt-dist
COPY nuxt.config.js nuxt.config.js
COPY server server
COPY config/default.js config/
COPY config/production.js config/
COPY config/custom-environment-variables.js config/
COPY contract contract

# Adding licence, manifests, etc.
COPY README.md BUILD.json* ./
COPY LICENSE .

# configure node webapp environment
ENV NODE_ENV production

# Default port of our webapps
EXPOSE 8080
Expand Down
17 changes: 12 additions & 5 deletions nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ const URL = require('url').URL
let config = { ...require('config') }
config.basePath = new URL(config.publicUrl + '/').pathname

const isBuilding = process.argv.slice(-1)[0] === 'build'
const isBuilding = process.argv[2] === 'build'

if (!config.proxyNuxt) {
if (process.env.NODE_ENV === 'production') {
const nuxtConfigInject = require('@koumoul/nuxt-config-inject')
if (isBuilding) config = nuxtConfigInject.prepare(config)
else nuxtConfigInject.replace(config, ['nuxt-dist/**/*', 'public/static/**/*'])
}

let vuetifyOptions = {}
if (isBuilding) {

if (process.env.NODE_ENV !== 'production' || isBuilding) {
const fr = require('vuetify/es5/locale/fr').default
const en = require('vuetify/es5/locale/en').default
vuetifyOptions = {
Expand Down Expand Up @@ -39,8 +40,14 @@ module.exports = {
srcDir: 'public/',
buildDir: 'nuxt-dist',
build: {
publicPath: '_nuxt/',
transpile: [/@koumoul/, 'easymde', 'marked'] // Necessary for "à la carte" import of vuetify components
publicPath: config.publicUrl + '/_nuxt/',
transpile: [ // Necessary for "à la carte" import of vuetify components
/@koumoul/,
/@data-fair/,
'easymde',
'marked',
'sanitize-html'
]
},
loading: { color: '#1e88e5' }, // Customize the progress bar color
plugins: [
Expand Down
Loading