Skip to content
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
6 changes: 6 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules/
build/
dist/
coverage/
*.config.ts
*.config.js
23 changes: 23 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2022,
"sourceType": "module",
"project": "./tsconfig.json"
},
"plugins": ["@typescript-eslint"],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"env": {
"node": true,
"es2022": true
},
"rules": {
"@typescript-eslint/no-unused-vars": [
"error",
{ "argsIgnorePattern": "^_" }
],
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-explicit-any": "warn"
}
}
18 changes: 18 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Build

on:
workflow_call:
outputs:
image-digests:
description: 'The output image digests'
value: ${{ jobs.build.outputs.image-digests }}

jobs:
build:
name: Build
uses: getdevopspro/github-actions/.github/workflows/build.yml@v6.0.3
with:
version-package: package.json
version-package-lock: package-lock.json
pre-lint-command: NODEAPP_UID=$(id -u) NODEAPP_RESTART_POLICY=no NODEAPP_COMMAND="bash -c 'npm ci --ignore-scripts; npm run lint'" docker compose up nodeapp --force-recreate --remove-orphans --abort-on-container-exit --exit-code-from nodeapp
pre-test-unit-command: NODEAPP_UID=$(id -u) NODEAPP_RESTART_POLICY=no NODEAPP_COMMAND="bash -c 'npm ci --ignore-scripts; npm run test'" docker compose up nodeapp --force-recreate --remove-orphans --abort-on-container-exit --exit-code-from nodeapp
18 changes: 18 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: PR

on:
pull_request:
types: [opened, synchronize, reopened]

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

permissions:
contents: read
packages: write

jobs:
ci:
name: CI
uses: ./.github/workflows/build.yaml
35 changes: 35 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Release

on:
push:
branches:
- main
- master
tags:
- 'v*'
paths-ignore:
- '**.md'

concurrency:
group: release-${{ github.workflow }}
cancel-in-progress: false

permissions:
contents: write
packages: write

jobs:
build:
name: CI
uses: ./.github/workflows/build.yaml

promote:
name: CI
needs: build
uses: getdevopspro/github-actions/.github/workflows/promote.yml@v6.0.3
with:
version-package: package.json
git-add-files: package.json
git-user-name: getdevopspro-cibot
git-user-email: 203600057+getdevopspro-cibot@users.noreply.github.com
image-digests: ${{ needs.build.outputs.image-digests }}
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
node_modules/
build/
dist/
.npm/
*.log
.env
.env.local
.DS_Store
coverage/
80 changes: 80 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Set default base image
ARG ARG_IMAGE_FROM=docker.io/node:22

# -----------------------------------------------------------------------------
# Stage 1: Nodeapp build
# -----------------------------------------------------------------------------
FROM ${ARG_IMAGE_FROM} AS nodeapp-base

WORKDIR /home/node/app

# -----------------------------------------------------------------------------
# Stage 2: Nodeapp build
# -----------------------------------------------------------------------------
FROM nodeapp-base AS nodeapp-build

COPY static /home/node/app/static
COPY *.json *.ts *.js *.cjs /home/node/app/
COPY src /home/node/app/src

RUN --mount=type=cache,target=/home/node/.npm,sharing=locked \
npm ci --ignore-scripts && \
npm run build && \
npm prune --omit=dev

# -----------------------------------------------------------------------------
# TARGET 1: Nodeapp dev image
# -----------------------------------------------------------------------------
FROM nodeapp-base AS nodeapp-dev

ARG NODE_ENV=development
ARG NODE_UID=1000
ENV NODE_UID=$NODE_UID
ENV NODE_ENV=$NODE_ENV
ENV NPM_CONFIG_PREFIX=/home/node/app/.npm
ENV NPM_CONFIG_CACHE=/home/node/app/.npm

RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
set -ex && \
apt-get update && \
apt-get install --no-install-recommends -y \
# Alphabetical order per best practice
# (To make finding packages in lists easier and to help avoid duplicates)
git \
curl \
make \
tar \
unzip \
zip

RUN usermod -u $NODE_UID node && \
groupmod -g $NODE_UID node && \
usermod -d /home/node -m node && \
chown -R $NODE_UID:$NODE_UID /home/node

USER $NODE_UID

CMD ["/bin/bash"]

# -----------------------------------------------------------------------------
# TARGET 2: Nodeapp image
# -----------------------------------------------------------------------------
FROM nodeapp-base AS nodeapp

ARG ENV=production
ARG PORT=3000
ENV NODE_ENV=$ENV

COPY --from=nodeapp-build --chown=node:root /home/node/app/package.json .
COPY --from=nodeapp-build --chown=node:root /home/node/app/node_modules node_modules/
COPY --from=nodeapp-build --chown=node:root /home/node/app/build build/

EXPOSE $PORT

CMD [ "node", "-r", "dotenv/config", "build" ]

# -----------------------------------------------------------------------------
# TARGET 3: Final image
# -----------------------------------------------------------------------------
FROM nodeapp AS final
12 changes: 12 additions & 0 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// docker-bake.hcl
target "docker-metadata-action" {}

target "build" {
inherits = ["docker-metadata-action"]
context = "./"
dockerfile = "Dockerfile"
platforms = [
"linux/amd64",
"linux/arm64",
]
}
23 changes: 23 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
services:
nodeapp:
image: ${NODEAPP_IMAGE:-nodeapp:dev}
user: '${NODEAPP_UID:-1000}'
working_dir: '${NODEAPP_WORKING_DIR:-/home/node/app}'
network_mode: 'host'
env_file:
- path: '${NODEAPP_ENV_FILE:-.env}'
required: false
restart: '${NODEAPP_RESTART_POLICY:-unless-stopped}'
build:
context: .
args:
NODE_UID: '${NODEAPP_UID:-1000}'
dockerfile: '${NODEAPP_DOCKERFILE:-Dockerfile}'
target: '${NODEAPP_DOCKERFILE_TARGET:-nodeapp-dev}'
environment:
- PORT=${NODEAPP_PORT:-5173}
- NODE_UID=${NODEAPP_UID:-1000}
volumes:
- './:${NODEAPP_WORKING_DIR:-/home/node/app}:rw,z'
stdin_open: ${NODEAPP_STDIN_OPEN:-false}
command: ${NODEAPP_COMMAND:-bash -c "npm i; npm run dev -- --host 0.0.0.0 --port ${NODEAPP_PORT:-5173}"}
Loading
Loading