Skip to content

Commit

Permalink
Update to node 20 and yarn 4 (#7)
Browse files Browse the repository at this point in the history
* Update to node 20 and yarn 4

* Fix dotenv security problem

* Remove deprecated @types/dotenv package

* Update yarn to 4.0.1

* Transition from localhost to local dev domain

* Scripts comments update

* Fix docu count
  • Loading branch information
stankolubomir authored Nov 7, 2023
1 parent b34d25a commit 39cedaa
Show file tree
Hide file tree
Showing 13 changed files with 1,873 additions and 1,924 deletions.
4 changes: 3 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
# GIT files
.git

# Managed by yarn
.yarn

# Ignore copy of prebuilt files and folders in to the docker container
node_modules
.yarn
dist
var
5 changes: 1 addition & 4 deletions .github/workflows/node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ on:
branches:
- main

env:
YARN_VERSION: '3.2.4'

jobs:
build:
strategy:
matrix:
node-version:
- '18'
- '20'
platform:
- ubuntu-latest

Expand Down
2 changes: 2 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
enableGlobalCache: false

nodeLinker: node-modules
20 changes: 17 additions & 3 deletions README-DEV.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,33 @@ Arguments:
- `--build` - Build all images to run fresh docker containers
- `-d` - Run docker containers in the detached mode as background processes

## 4. (Optional) Run dev watch node server
### 4. Add local domain to hosts

Add this entry to your hosts:

127.0.0.1 notification-server.anzusystems.local

- Linux/Mac location:

`/etc/hosts`

- Windows location

`C:\Windows\System32\drivers\etc\hosts`

## 5. (Optional) Run dev watch node server

By default the `docker-compose` command will autostart node server `yarn dev` with logs in `var/log/node-server.log` file.

_Hint: You can disable node server autostart with variable `DOCKER_NODE_AUTOSTART=false` in `.env.docker.local`. You have to restart the docker-compose to apply the change._

### 4.a. (Optional) Stop all running node servers
### 5.a. (Optional) Stop all running node servers

You must stop the running node server with the command:

bin/run stop

### 4.b. (Optional) Start dev watch
### 5.b. (Optional) Start dev watch

Run `watch` node server (See below in the command description for more command line options):

Expand Down
6 changes: 3 additions & 3 deletions bin/bash
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# Script used to run bash in the application docker container
# Script used to run bash in the application container

PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd)"
USER_SWITCH="--user node"
Expand All @@ -8,10 +8,10 @@ cd "${PROJECT_ROOT}" || exit 1

function help() {
echo -en "$(printf %q "${BASH_SOURCE[0]}") [OPERATION] [OPTIONS]...
\nScript used to run bash in the application docker container
\nScript used to run bash in the application container
Options:
--root (Optional) Run bash as root in the docker container
--root (Optional) Run bash as root in the application container
Examples:
$(printf %q "${BASH_SOURCE[0]}") --root
Expand Down
2 changes: 1 addition & 1 deletion bin/build
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# Script used to run build in the application docker container
# Script used to run build in the application container

PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd)"
cd "$PROJECT_ROOT" || exit 1
Expand Down
16 changes: 8 additions & 8 deletions bin/run
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# Script used to run node server in the application docker container according to specified arguments
# Script used to run node dev or prod server in the application container

PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd)"
ARGS="$*"
Expand All @@ -13,7 +13,7 @@ cd "${PROJECT_ROOT}" || exit 1

function help() {
echo -en "$(printf %q "${BASH_SOURCE[0]}") [OPERATION] [OPTIONS]...
\nScript used to run node server in the application docker container according to specified arguments
\nScript used to run node dev or prod server in the application container
Operations:
dev Start dev server
Expand All @@ -36,7 +36,7 @@ function help() {
function yarn_run() {
RUN_YARN_OPERATION="$1"
rm -f "/var/www/html/var/log/${RUN_YARN_OPERATION}.log"
tail -F "/var/www/html/var/log/${RUN_YARN_OPERATION}.log" 2>/dev/null &
tail -n 0 -F "/var/www/html/var/log/${RUN_YARN_OPERATION}.log" 2>/dev/null &
yarn "${RUN_YARN_OPERATION}" 2>>"/var/www/html/var/log/${RUN_YARN_OPERATION}.log"
}

Expand Down Expand Up @@ -93,12 +93,12 @@ if [ -z ${RUN_YARN_OPERATION} ]; then
fi

if [ -f /.dockerenv ]; then
echo "[INFO] Stopping all node processes"
if supervisorctl status "node-server" | grep -q RUNNING; then
supervisorctl stop "node-server"
fi
pkill node
if ${RUN_YARN_STOP}; then
echo "[INFO] Stopping all node processes"
if supervisorctl status "node-server" | grep -q RUNNING; then
supervisorctl stop "node-server"
fi
pkill node
exit
fi

Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
context: .
dockerfile: docker/app/local/Dockerfile
environment:
- VIRTUAL_HOST=notification-server.anzusystems.localhost
- VIRTUAL_HOST=notification-server.anzusystems.local
- VIRTUAL_PORT=8080
env_file:
- .env.docker.dist
Expand All @@ -18,7 +18,7 @@ services:
ports:
- ${NGINX_PORT:-8490}:8080
- ${NGINX_UPSTREAM_WEBSOCKET_PORT:-3410}:3005
hostname: notification-server.anzusystems.localhost
hostname: notification-server.anzusystems.local
networks:
anzusystems_network:
aliases:
Expand Down
38 changes: 7 additions & 31 deletions docker/app/local/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:18-bookworm-slim
FROM node:20-bookworm-slim

# ----------------------------------------------------------------------------------------------------------------------
# ENVIRONMENT VARIABLES
Expand All @@ -9,16 +9,15 @@ ARG DOCKER_GROUP_ID
# Versions
# Nginx version
ENV NGINX_VERSION=1.24.0 \
NGINX_NJS_VERSION=0.7.12 \
NGINX_NJS_VERSION=0.8.1 \
NGINX_PKG_RELEASE=1~bookworm \
# Supervisor version
SUPERVISOR_VERSION=4.2.5 \
SUPERVISOR_PKG_RELEASE=1 \
# NPM version
NPM_VERSION=9.7.2 \
NPM_VERSION=10.2.1 \
# Yarn version
DOCKER_YARN_VERSION=3.6.0 \
DOCKER_YARN_PLUGIN_OUTDATED=3.2.4
DOCKER_YARN_VERSION=4.0.1
# Common environment variables
ENV CONTAINER_STOP_LOG_FILE="/var/www/html/var/log/container_stop.log" \
COREPACK_HOME="/usr/lib/node/corepack" \
Expand All @@ -44,9 +43,6 @@ ENV RUN_DEPS="ca-certificates \
procps \
vim \
wget"
# Yarn plugins
ENV OFFICIAL_YARN_PLUGINS="interactive-tools" \
UNOFFICIAL_YARN_PLUGINS="outdated=https://mskelton.dev/yarn-outdated/v${DOCKER_YARN_PLUGIN_OUTDATED}"

# ----------------------------------------------------------------------------------------------------------------------
# PACKAGES
Expand All @@ -60,31 +56,13 @@ RUN apt-get update && \
rm -rf /var/lib/apt/lists/*

# ----------------------------------------------------------------------------------------------------------------------
# NPM
# Install static npm version
# NPM + YARN
# Install static npm and yarn version
# ----------------------------------------------------------------------------------------------------------------------
RUN npm install --location=global npm@${NPM_VERSION} && \
mkdir -p ${COREPACK_HOME} && \
corepack prepare yarn@${DOCKER_YARN_VERSION} --activate && \
corepack enable && \
# Install yarn plugins
mkdir -p /home/node/.yarn/plugins/@yarnpkg && \
echo "plugins:" >> /home/node/.yarnrc.yml && \
for plugin in ${OFFICIAL_YARN_PLUGINS}; do \
wget -q -O /home/node/.yarn/plugins/@yarnpkg/plugin-$plugin.cjs https://github.com/yarnpkg/berry/raw/@yarnpkg/cli/${DOCKER_YARN_VERSION}/packages/plugin-$plugin/bin/%40yarnpkg/plugin-$plugin.js && \
echo " - path: /home/node/.yarn/plugins/@yarnpkg/plugin-$plugin.cjs" >> /home/node/.yarnrc.yml; \
echo " spec: \"@yarnpkg/plugin-$plugin\"" >> /home/node/.yarnrc.yml; \
done && \
for plugin in ${UNOFFICIAL_YARN_PLUGINS}; do \
plugin_name=${plugin%%=*} && \
plugin_url=${plugin#*=} && \
wget -q -O /home/node/.yarn/plugins/@yarnpkg/plugin-$plugin_name.cjs $plugin_url && \
echo " - path: /home/node/.yarn/plugins/@yarnpkg/plugin-$plugin_name.cjs" >> /home/node/.yarnrc.yml; \
echo " spec: \"@yarnpkg/plugin-$plugin_name\"" >> /home/node/.yarnrc.yml; \
done && \
# Node cache cleanup
npm cache clean --force && \
yarn cache clean --all
corepack enable

# ----------------------------------------------------------------------------------------------------------------------
# NGINX
Expand Down Expand Up @@ -126,8 +104,6 @@ RUN ln -sf /dev/stdout /var/log/nginx/access.log && \
${YARN_CACHE_FOLDER} \
/etc/nginx \
/home/node/.npmrc \
/home/node/.yarn \
/home/node/.yarnrc.yml \
/run/nginx \
/usr/local/bin \
/usr/local/lib/node_modules \
Expand Down
1 change: 0 additions & 1 deletion docker/nginx-proxy/my_proxy.conf

This file was deleted.

30 changes: 0 additions & 30 deletions docker/pubsub/Dockerfile

This file was deleted.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "notification-server",
"packageManager": "yarn@3.2.4",
"packageManager": "yarn@4.0.1",
"version": "1.0.0",
"description": "",
"license": "Apache-2.0",
Expand All @@ -26,7 +26,7 @@
"dependencies": {
"@google-cloud/pubsub": "^3.1.0",
"cookies": "^0.8.0",
"dotenv": "^16.0.1",
"dotenv": "^16.3.1",
"jsonwebtoken": "^9.0.0",
"reflect-metadata": "^0.1.13",
"typedi": "^0.10.0",
Expand All @@ -36,7 +36,6 @@
},
"devDependencies": {
"@types/cookies": "^0.7.7",
"@types/dotenv": "^8.2.0",
"@types/jest": "^28.1.6",
"@types/jsonwebtoken": "^9.0.2",
"@types/node": "^18.6.3",
Expand Down
Loading

0 comments on commit 39cedaa

Please sign in to comment.