Skip to content

Commit

Permalink
feat: switch to bundled esbuild deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
Vilsol committed Jan 26, 2024
1 parent ece0114 commit 8a138b5
Show file tree
Hide file tree
Showing 9 changed files with 819 additions and 2,987 deletions.
40 changes: 13 additions & 27 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ on: push

jobs:
build:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Setup NodeJS
uses: actions/setup-node@v1
- uses: actions/setup-node@v4
with:
node-version: '20.8.0'
node-version-file: '.nvmrc'

- name: Install Dependencies
run: npm ci
Expand All @@ -21,54 +19,42 @@ jobs:
run: npm run build

test:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
needs: build
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Setup NodeJS
uses: actions/setup-node@v1
- uses: actions/setup-node@v4
with:
node-version: '20.8.0'

- name: Setup System
uses: restorecommerce/setup-system-action@v1
node-version-file: '.nvmrc'

- name: Install Dependencies
run: npm ci

- name: Test
run: npm run test && npm run lcov-report

- name: Coveralls
uses: coverallsapp/github-action@master
- uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

image:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
needs: build
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Setup buildx
uses: docker/setup-buildx-action@v1
- uses: docker/setup-buildx-action@v3

- name: Set variables
id: vars
run: |
echo ::set-output name=version_tag::$(echo ${GITHUB_REF#refs/*/})
echo ::set-output name=repo_name::$(echo ${GITHUB_REPOSITORY#*/*})
- name: Build
uses: docker/build-push-action@v2
- uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64
push: false
build-args: |
APP_HOME=/home/node/${{ steps.vars.outputs.repo_name }}
cache-from: |
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/pr-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: "Lint PR"

on:
pull_request_target:
types:
- opened
- edited
- synchronize

permissions:
pull-requests: read

jobs:
main:
name: pr-lint
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62 changes: 32 additions & 30 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
name: release
name: Release

on:
push:
tags:
- v*
branches:
- master

permissions:
contents: read

jobs:
release:
runs-on: ubuntu-20.04
permissions:
contents: write
issues: write
pull-requests: write
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Login to DockerHub
uses: docker/login-action@v1
- uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.CR_PAT }}

- uses: docker/setup-buildx-action@v1
- uses: docker/setup-buildx-action@v3
with:
install: true

Expand All @@ -34,28 +38,26 @@ jobs:
run: |
echo ::set-output name=repo_name::$(echo ${GITHUB_REPOSITORY#*/*})
- name: Docker meta
- uses: docker/metadata-action@v5
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
with:
images: |
${{ github.repository }}
ghcr.io/${{ github.repository }}
tag-sha: true
tag-semver: |
{{version}}
{{major}}.{{minor}}
- name: Build and push
uses: docker/build-push-action@v2
images: ${{ github.repository }}

- uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64
push: true
load: true
build-args: |
APP_HOME=/home/node/${{ steps.vars.outputs.repo_name }}
cache-from: |
${{ github.repository }}:latest
tags: ${{ steps.docker_meta.outputs.tags }}
tags: ${{ github.repository }}
labels: ${{ steps.docker_meta.outputs.labels }}

- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'

- name: Install Dependencies
run: npm clean-install

- run: npx [email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23 changes: 23 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Contributing Guidelines

## Commit Messages

This repository uses [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) and [commitlint](https://commitlint.js.org)
to standardize the commit messages.

## Development Flow

This repository follows a gitflow-style development.

The `main`/`master` branch is locked, and only allows pull requests.
Any change in the `main`/`master` branch gets automatically released via [semantic-release](https://github.com/semantic-release/semantic-release).

The `next` branch gets merged into `main`/`master` on an unscheduled basis.

Any change to the repository requires a new branch from the `next` branch, which then gets merged back into it with a pull request.

The pull request title must follow the same rules as commit messages and it gets linted.

The following diagram visualizes the development flow:

![development flow](./.github/development-flow.png)
19 changes: 11 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
### Base
FROM node:20.8.0-alpine3.18 as base
### Build
FROM node:20.8.0-alpine3.18 as build
ENV NO_UPDATE_NOTIFIER=true

RUN apk add --no-cache git
Expand All @@ -12,10 +12,6 @@ WORKDIR $APP_HOME
COPY package.json package.json
COPY package-lock.json package-lock.json


### Build
FROM base as build

RUN npm ci

COPY --chown=node:node . .
Expand All @@ -24,9 +20,16 @@ RUN npm run build


### Deployment
FROM base as deployment
FROM node:20.8.0-alpine3.18 as deployment

ENV NO_UPDATE_NOTIFIER=true

RUN npm ci --only=production
USER node
ARG APP_HOME=/home/node/srv
WORKDIR $APP_HOME

COPY package.json package.json
COPY package-lock.json package-lock.json

COPY --chown=node:node . $APP_HOME
COPY --chown=node:node --from=build $APP_HOME/lib $APP_HOME/lib
Expand Down
4 changes: 4 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ Please consult the documentation for using it:
- *link:https://docs.restorecommerce.io/architecture/index.html[Restorecommerce Architecture]*
Part of link:https://github.com/restorecommerce[Restorecommerce].

== Contributing

Read more in link:{docdir}/CONTRIBUTING.md[CONTRIBUTING.md]
Loading

0 comments on commit 8a138b5

Please sign in to comment.