Skip to content

Commit

Permalink
add build script
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieVangeysel committed Nov 28, 2024
1 parent 5b90042 commit 1f97215
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 35 deletions.
49 changes: 15 additions & 34 deletions api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,46 +1,27 @@
# ---- Build ----
FROM --platform=linux/amd64 groupclaes/npm AS build

# change the working directory to new exclusive app folder
# ---- deps ----
FROM groupclaes/npm:10 AS depedencies
WORKDIR /usr/src/app

# copy project file
COPY ./ ./

# install node packages
RUN npm install

# create esbuild package
RUN esbuild ./index.ts --bundle --platform=node --minify --packages=external --external:'./config' --outfile=index.min.js
COPY package.json ./package.json
COPY .npmrc ./.npmrc

RUN npm install --omit=dev --ignore-scripts

# ---- Deps ----
FROM --platform=linux/amd64 groupclaes/npm AS depedencies

# change the working directory to new exclusive app folder
WORKDIR /usr/src/app
# ---- build ----
FROM depedencies AS build
COPY index.ts ./index.ts
COPY src/ ./src

# copy package file
COPY package.json ./
RUN npm install --ignore-scripts && npm run build

# install node packages
RUN npm install
# ---- final ----
FROM groupclaes/node:20


# --- release ---
FROM --platform=linux/amd64 groupclaes/node AS release

# set current user to node
USER node

# change the working directory to new exclusive app folder
WORKDIR /usr/src/app

# copy dependencies
COPY --chown=node:node --from=depedencies /usr/src/app ./

# copy project file
COPY --chown=node:node --from=build /usr/src/app/index.min.js ./
# removed --chown=node:node
COPY --from=depedencies /usr/src/app ./
COPY --from=build /usr/src/app/index.min.js ./

# command to run when intantiate an image
CMD ["node","index.min.js"]
19 changes: 19 additions & 0 deletions api/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
docker_tag="latest"
docker_reg="groupclaes"
PACKAGE_VERSION=$(cat package.json \
| grep version \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g' \
| tr -d '[[:space:]]')
PACKAGE_NAME=$(cat package.json \
| grep name \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g' \
| tr -d '[[:space:]]')

echo "building docker images ${docker_reg}/${PACKAGE_NAME}:${docker_tag} and ${docker_reg}/${PACKAGE_NAME}:${PACKAGE_VERSION}"

docker buildx build --platform=linux/amd64 -t "${docker_reg}/${PACKAGE_NAME}:${docker_tag}" -t "${docker_reg}/${PACKAGE_NAME}:${PACKAGE_VERSION}" -f Dockerfile --sbom=true --provenance=true --push .
3 changes: 2 additions & 1 deletion api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.1.0",
"description": "",
"scripts": {
"build": "esbuild ./index.ts --bundle --platform=node --minify --packages=external --external:'./config' --outfile=index.min.js",
"test": "tap --reporter=list --show-full-coverage"
},
"author": {
Expand All @@ -19,4 +20,4 @@
"@types/node": "^20.16.5",
"esbuild": "^0.19.12"
}
}
}

0 comments on commit 1f97215

Please sign in to comment.