Skip to content

Commit

Permalink
[SCSE-247] Build merch app as docker image (#100)
Browse files Browse the repository at this point in the history
* Added Dockerfile, fixed package.lock and tsconfig

* Fixed CD pipeline for merch image build

* Fixed docker compose merch image

* Updated Dockerfile

* Directory clean up

* bump turbo version

* update gitignore

* temp fix build errors

* fix merch docker image

* add color to turbo build step in dockerfile

* update merch deps in package.json

---------

Co-authored-by: Dyllon <dyllon.g@outlook.com>
  • Loading branch information
aryans1204 and RealDyllon authored Jun 14, 2023
1 parent cb37937 commit bc7593f
Show file tree
Hide file tree
Showing 15 changed files with 945 additions and 741 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/cd-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,37 @@ jobs:
ghcr.io/${{ github.repository_owner }}/website/cms:${{ github.sha }}
ghcr.io/${{ github.repository_owner }}/website/cms:latest
build-merch:
name: Build Merch Docker Image
runs-on: ubuntu-22.04
steps:
- name: Checkout repo
uses: actions/checkout@v3

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

- name: Build and push
uses: docker/build-push-action@v2
with:
file: ./apps/merch/Dockerfile
context: .
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/website/merch:${{ github.sha }}
ghcr.io/${{ github.repository_owner }}/website/merch:latest
deploy-to-staging:
name: Deploy To Staging
runs-on: ubuntu-22.04
needs:
- build-cms
- build-merch
steps:
- name: Checkout repo
uses: actions/checkout@v3
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ node_modules
# testing
coverage

# build
**/build
**/out
**/dist

# next.js
.next/
out/
Expand Down
53 changes: 53 additions & 0 deletions apps/merch/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
FROM node:16-alpine AS builder

RUN apk add --no-cache libc6-compat
RUN apk update

# Set working directory
WORKDIR /app
RUN yarn global add turbo
COPY . .
RUN rm -rf **/node_modules **/build **/dist **/out **/.turbo
RUN rm -rf **/.env
RUN turbo prune --scope=merch --docker

FROM node:16-alpine AS installer
# Add lockfile and package.json's of isolated subworkspace
RUN apk add --no-cache libc6-compat
RUN apk update
WORKDIR /app

# First install dependencies (as they change less often)
#COPY .gitignore .gitignore
COPY --from=builder /app/out/json/ .
COPY --from=builder /app/out/yarn.lock ./yarn.lock
RUN yarn install

# Build the project and its dependencies
COPY --from=builder /app/out/full/ .
COPY turbo.json turbo.json
RUN yarn turbo run build --filter=merch... --color

FROM node:16-alpine AS runner

WORKDIR /app

# Don't run production as root
#RUN addgroup --system --gid 1001 expressjs
#RUN adduser --system --uid 1001 expressjs
#USER expressjs

COPY --from=installer /app .
RUN rm -rf /app/apps/merch/src

WORKDIR /app/apps/merch

#ENV NODE_ENV=production
#ENV PAYLOAD_CONFIG_PATH=dist/payload.config.js
#ENV BABEL_DISABLE_CACHE=1

#EXPOSE 80
EXPOSE 7001

CMD ["node", "dist/index.js"]

12 changes: 8 additions & 4 deletions apps/merch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,30 @@
"name": "merch",
"description": "NTU SCSE Merch Backend",
"version": "0.1.0",
"main": "dist/server.js",
"main": "dist/index.js",
"license": "Apache-2.0",
"scripts": {
"dev": "nodemon src/server.ts",
"build": "tsup src/index.ts --format cjs",
"start": "node dist/index.js",
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
"dev": "tsup src/index.ts --format cjs --watch --onSuccess \"node dist/index.js\"",
"lint": "TIMING=1 eslint \"**/*.ts*\"",
"lint:fix": "TIMING=1 eslint --fix \"**/*.ts*\""
},
"dependencies": {
"express": "^4.17.1"
"express": "^4.17.1",
"nodelogger": "*"
},
"devDependencies": {
"@types/cookie-parser": "^1.4.3",
"@types/express": "^4.17.9",
"@types/morgan": "^1.9.4",
"cookie-parser": "^1.4.6",
"morgan": "^1.10.0",
"nodelogger": "*",
"nodemon": "^2.0.6",
"ts-node": "^9.1.1",
"tsconfig": "*",
"tsup": "^6.7.0",
"types": "*",
"typescript": "^4.8.4",
"winston": "^3.8.2"
Expand Down
File renamed without changes.
3 changes: 1 addition & 2 deletions deployments/staging/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ services:
- "traefik.http.routers.cms.rule=Host(`cms.staging.ntuscse.com`, `13.213.116.60`, `localhost`)"
- "traefik.http.routers.cms.entrypoints=websecure"
- "traefik.http.routers.cms.tls.certresolver=myresolver"

mongo:
container_name: mongo
image: mongo:latest
Expand All @@ -62,7 +61,7 @@ services:

merch:
container_name: merch
image: nginx
image: ghcr.io/ntuscse/website/merch:latest
networks:
cms_network:
ipv4_address: 10.5.0.4
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"devDependencies": {
"eslint-config-custom": "*",
"prettier": "^2.8.1",
"turbo": "^1.8.2"
"turbo": "^1.10.1"
},
"engines": {
"node": ">=16.0.0",
Expand Down
19 changes: 16 additions & 3 deletions packages/nodelogger/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
{
"name": "nodelogger",
"version": "0.0.1",
"main": "index.ts",
"types": "index.ts",
"private": true,
"main": "./dist/index.js",
"source": "./src/index.ts",
"types": "./dist/index.d.ts",
"files": [
"dist/**"
],
"license": "Apache-2.0",
"scripts": {
"build": "tsc",
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
"dev": "tsc -w",
"lint": "TIMING=1 eslint \"**/*.ts*\"",
"lint:fix": "TIMING=1 eslint --fix \"**/*.ts*\""
},
Expand All @@ -14,5 +22,10 @@
"morgan": "^1.10.0",
"winston": "^3.8.2"
},
"devDependencies": {}
"devDependencies": {
"eslint": "^7.32.0",
"eslint-config-custom": "*",
"tsconfig": "*",
"typescript": "^4.5.2"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
29 changes: 27 additions & 2 deletions packages/nodelogger/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
{
"extends": "tsconfig/node.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src",
"module": "commonjs",
"target": "es2017",
"lib": [
"es2017",
"esnext.asynciterable"
],
"sourceMap": true,
"declaration": true,
"strict": true,
"noImplicitAny": true,
"moduleResolution": "node",
"baseUrl": "./",
"paths": {
"*": [
"node_modules/*",
"src/types/*"
]
},
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"include": [
"**/*.js",
"**/*.ts",
"src/**/*.ts"
],
"exclude": [
"dist",
Expand Down
3 changes: 2 additions & 1 deletion packages/schemas/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"name": "schemas",
"description": "Schemas for graphql and other things"
"description": "Schemas for graphql and other things",
"version": "0.0.1"
}
2 changes: 1 addition & 1 deletion packages/tsconfig/node.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"target": "es6",
"moduleResolution": "node",
"sourceMap": true,
"outDir": "dist"
"outDir": "./dist"
},
"lib": ["esnext"]
}
Loading

1 comment on commit bc7593f

@vercel
Copy link

@vercel vercel bot commented on bc7593f Jun 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

website-ui-storybook – ./packages/ui

website-ui-storybook-cse-it.vercel.app
storybook.ui.dev.ntuscse.com
website-ui-storybook-git-main-cse-it.vercel.app

Please sign in to comment.