Skip to content

Commit

Permalink
Add some voulmizer to the folicles (#60)
Browse files Browse the repository at this point in the history
* Add some voulmizer to the folicles

* Specify node_env for all the ci jobs

* Expose node_env in the server
  • Loading branch information
KevinMind committed Mar 28, 2024
1 parent 1fe8911 commit bb958f6
Show file tree
Hide file tree
Showing 16 changed files with 1,388 additions and 28 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
node_modules
5 changes: 5 additions & 0 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ inputs:
username:
required: false
description: "Username for the registry"
node_env:
required: false
description: "Node environment"
default: "production"

outputs:
tags:
Expand Down Expand Up @@ -78,3 +82,4 @@ runs:
cache-to: type=gha,mode=max
build-args: |
VERSION=${{ steps.meta.outputs.tags }}
NODE_ENV=${{ inputs.node_env }}
1 change: 1 addition & 0 deletions .github/workflows/deploy.development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
push: true
username: ${{ github.actor}}
password: ${{ secrets.GITHUB_TOKEN }}
node_env: production

- name: Deploy
uses: ./.github/actions/deploy
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/deploy.production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
push: true
username: ${{ github.actor}}
password: ${{ secrets.GITHUB_TOKEN }}
node_env: production

- name: Deploy
uses: ./.github/actions/deploy
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/deploy.staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
push: true
username: ${{ github.actor}}
password: ${{ secrets.GITHUB_TOKEN }}
node_env: production

- name: Deploy
uses: ./.github/actions/deploy
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ name: Publish

on:
workflow_dispatch:
inputs:
node_env:
description: 'Node environment'
required: true
default: 'production'

permissions:
contents: read
Expand All @@ -19,6 +24,7 @@ jobs:
push: true
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
node_env: ${{ inputs.node_env }}
- name: Notify (success)
if: success()
uses: ./.github/actions/slack
Expand Down
12 changes: 8 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/build
id: build
- id: build
uses: ./.github/actions/build
with:
node_env: development
- name: Test
uses: ./.github/actions/run
with:
Expand All @@ -28,8 +30,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/build
id: build
- id: build
uses: ./.github/actions/build
with:
node_env: development
- name: Lint
uses: ./.github/actions/run
with:
Expand Down
9 changes: 7 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
dist
node_modules
dist/**
node_modules/**


.npm
.bash_history
.cache
50 changes: 37 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,50 @@
ARG HOME=/app UID=9500 GID=9500 VERSION="base"
ARG NODE_ENV=production

# Define the base image, here we are root.
FROM node:18 as base

WORKDIR /app
RUN touch /is-docker

# Define the user and working directory, everything from this is user land
FROM base as user

ARG HOME UID GID

RUN <<EOF
groupadd -g ${GID} user
useradd -u ${UID} -g ${GID} -s /sbin/nologin -d ${HOME} user
EOF

USER user
WORKDIR ${HOME}

FROM user as build

RUN --mount=type=bind,src=package.json,dst=/app/package.json \
npm install
ARG HOME
# Always development for building as we need to build the code
ENV NODE_ENV=development

RUN \
--mount=type=bind,src=package.json,dst=/app/package.json \
--mount=type=bind,src=src,dst=/app/src/ \
--mount=type=bind,src=tsconfig.json,dst=/app/tsconfig.json \
npm run build
--mount=type=bind,source=src,target=${HOME}/src \
--mount=type=bind,source=package.json,target=${HOME}/package.json \
--mount=type=bind,source=package-lock.json,target=${HOME}/package-lock.json \
--mount=type=bind,source=tsconfig.json,target=${HOME}/tsconfig.json \
<<EOF
npm install --loglevel=verbose --no-save
npm run build
EOF

FROM base as final
FROM user as final

ARG VERSION="base"
ARG HOME VERSION NODE_ENV

ENV VERSION=${VERSION}
ENV VERSION=${VERSION} NODE_ENV=${NODE_ENV}

COPY --from=base /app/dist /app/dist
COPY package.json /app/package.json
COPY --from=build ${HOME}/dist ${HOME}/dist
COPY package.json package-lock.json ${HOME}/

RUN npm i --omit=dev --no-save
RUN npm install --loglevel=verbose --no-save

EXPOSE 3000

39 changes: 39 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.PHONY: default
default: help

.PHONY: up
up: ## Build and start containers
mkdir -p node_modules
mkdir -p dist
docker compose up -d --build

.PHONY: build
build: ## Build the app container
docker compose build --no-cache --progress=plain

.PHONY: down
down: ## Stop and remove containers, networks, images, and volumes
docker compose down $(ARGS)

.PHONY: clean
clean: ## Remove all containers, networks, images, and volumes
make down ARGS="--rmi all --volumes"
docker builder prune -af

.PHONY: shell
shell: ## Access to the shell of the app docker container
docker compose exec app /bin/bash

.PHONY: install
install: ## Install dependencies
docker compose exec app npm install $(ARGS) --loglevel=verbose

.PHONY: test
test: ## Run tests
docker compose exec app npm test $(ARGS)

.PHONY: help
help:
@echo "Please use 'make <target>' where <target> is one of the following commands.\n"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' Makefile | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

26 changes: 26 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: '3.8'
services:
app:
build:
context: .
args:
NODE_ENV: development
volumes:
- node_modules:/app/node_modules
- dist:/app/dist
- .:/app:delegated
command: npm run dev
ports:
- 3000:3000

volumes:
node_modules:
driver_opts:
type: "none"
o: "bind"
device: "${PWD}/node_modules"
dist:
driver_opts:
type: "none"
o: "bind"
device: "${PWD}/dist"
Loading

0 comments on commit bb958f6

Please sign in to comment.