diff --git a/.github/workflows/build-node.yml b/.github/workflows/build-node.yml new file mode 100644 index 0000000..5bbd42a --- /dev/null +++ b/.github/workflows/build-node.yml @@ -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 diff --git a/.github/workflows/schedule-trigger.yml b/.github/workflows/schedule-trigger.yml index 853a14a..d855ad1 100644 --- a/.github/workflows/schedule-trigger.yml +++ b/.github/workflows/schedule-trigger.yml @@ -14,6 +14,7 @@ jobs: strategy: matrix: image: + - node - prestashop - shopware - wordpress diff --git a/.github/workflows/schedule.yml b/.github/workflows/schedule.yml index c5e5a9b..226a596 100644 --- a/.github/workflows/schedule.yml +++ b/.github/workflows/schedule.yml @@ -6,6 +6,7 @@ on: - main paths: + - images/node/** - images/prestashop/** - images/shopware/** - images/wordpress/** @@ -17,6 +18,7 @@ on: required: true type: choice options: + - node - prestashop - shopware - wordpress @@ -27,6 +29,7 @@ jobs: strategy: matrix: image: + - node - prestashop - shopware - wordpress diff --git a/images/node/Dockerfile b/images/node/Dockerfile new file mode 100644 index 0000000..29ac6b3 --- /dev/null +++ b/images/node/Dockerfile @@ -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"]