Skip to content

Commit

Permalink
feat: add node images
Browse files Browse the repository at this point in the history
  • Loading branch information
EdieLemoine committed Sep 19, 2024
1 parent b2d067f commit 8c045fd
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 0 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/build-node.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: 'Build node images'

on:
workflow_dispatch:

permissions:
contents: read
packages: write

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}

jobs:
build:
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
node:
- 16
- 18
- 20
- 22
yarn:
- 1
- 2
- 3
- 4
env:
NODE_LATEST: 22
YARN_LATEST: 4
steps:
- uses: actions/checkout@v4

- uses: ./.github/actions/login-ghcr
with:
token: ${{ secrets.GITHUB_TOKEN }}

- uses: ./.github/actions/build-push
with:
registry: ghcr.io
cache-mode: 'min'
context: images/node
image: myparcelnl/node
latest: ${{ matrix.node == env.NODE_LATEST }} && ${{ matrix.yarn == env.YARN_LATEST }}
suffix: ${{ matrix.node }}-yarn${{ matrix.yarn }}
build-args: |
NODE_VERSION=${{ matrix.node }}
YARN_VERSION=${{ matrix.yarn }}
notify-on-failure:
needs:
- build
if: always() && contains(needs.*.result, 'failure')
uses: myparcelnl/actions/.github/workflows/notify-on-failure.yml@v4
secrets: inherit
1 change: 1 addition & 0 deletions .github/workflows/schedule-trigger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
strategy:
matrix:
image:
- node
- prestashop
- shopware
- wordpress
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/schedule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
- main

paths:
- images/node/**
- images/prestashop/**
- images/shopware/**
- images/wordpress/**
Expand All @@ -17,6 +18,7 @@ on:
required: true
type: choice
options:
- node
- prestashop
- shopware
- wordpress
Expand All @@ -27,6 +29,7 @@ jobs:
strategy:
matrix:
image:
- node
- prestashop
- shopware
- wordpress
Expand Down
49 changes: 49 additions & 0 deletions images/node/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
ARG NODE_VERSION="20"

##########
# Node
##########
FROM node:${NODE_VERSION}-alpine AS node

ARG YARN_VERSION="4"

ENV NODE_VERSION=${NODE_VERSION}
ENV YARN_VERSION=${YARN_VERSION}
ENV YARN_CACHE_FOLDER=/tmp/.cache/yarn
ENV YARN_IGNORE_NODE=1

WORKDIR /app

RUN NODE_MAJOR_VERSION=$(echo $NODE_VERSION | cut -d. -f1) && \
NODE_MINOR_VERSION=$(echo $NODE_VERSION | cut -d. -f2) && \
# if node version is 18 and up, use corepack
if [ "$NODE_MAJOR_VERSION" -lt 18 ]; then \
# expand YARN_VERSION to the full version number with #.x \
if [[ ! "$YARN_VERSION" =~ ^1 ]]; then \
if [[ "$YARN_VERSION" =~ ^[0-9]+$ ]]; then \
YARN_VERSION="${YARN_VERSION}.x"; \
fi && \
yarn policies set-version stable && \
yarn set version $YARN_VERSION; \
fi && \
chmod +x ./.yarn/releases/yarn-*.cjs && \
# replace the default yarn in bin with the new version in .yarn/releases/yarn-x.x.x.cjs \
cp ./.yarn/releases/yarn-*.cjs "$(which yarn)"; \
else \
# If node version is 18 and up, use corepack
corepack enable && \
corepack prepare "yarn@${YARN_VERSION}" --activate; \
fi && \
if [[ "$YARN_VERSION" =~ ^1 ]]; then \
# Yarn 1.x
yarn config set cache-folder "$YARN_CACHE_FOLDER"; \
else \
# Yarn 2+
yarn config set --home enableTelemetry 0 && \
yarn config set --home enableGlobalCache false && \
yarn config set --home cacheFolder "$YARN_CACHE_FOLDER"; \
fi

LABEL org.opencontainers.image.description="Node.js ${NODE_VERSION} with Yarn ${YARN_VERSION} installed"

CMD ["node"]

0 comments on commit 8c045fd

Please sign in to comment.