Skip to content

Commit

Permalink
feat(package): upgrade docker (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hagith authored Oct 8, 2024
1 parent 9e83b75 commit d450e73
Show file tree
Hide file tree
Showing 14 changed files with 324 additions and 104 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.git
node_modules
dist
scripts
**/Dockerfile
docker-compose*
.dockerignore
2 changes: 1 addition & 1 deletion .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = {
},
overrides: [
{
files: ['**/*.js'],
files: ['**/*.{js,cjs}'],
env: {
node: true,
},
Expand Down
43 changes: 43 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
FROM node:20-slim AS base

ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"

RUN corepack enable

FROM base AS build

COPY . /usr/src/app
WORKDIR /usr/src/app
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
RUN pnpm build
RUN pnpm deploy --filter=api --prod /prod/api
RUN pnpm deploy --filter=web --prod /prod/web

FROM base AS api

WORKDIR /app
COPY --from=build /prod/api /app
EXPOSE 3000
CMD ["node", "dist/main.js"]

FROM nginx:stable AS web

# This tool converts env vars into json to be injected into the config
ADD https://s3.amazonaws.com/se-com-docs/bins/json_env /usr/local/bin/
RUN chmod +x /usr/local/bin/json_env

COPY apps/web/docker/nginx.conf /etc/nginx/conf.d/default.conf
COPY apps/web/docker/expires.conf /etc/nginx/conf.d/expires.conf
COPY apps/web/docker/entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh

ENV CONFIG_FILE_PATH=/app/config/app.json

WORKDIR /app
COPY --from=build /prod/web/dist /app
RUN rm -rf /app/config/*

ENTRYPOINT ["entrypoint.sh"]

CMD ["nginx", "-g", "daemon off;"]
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,53 @@
# [Vue.js](https://vuejs.org/) + [NestJS](https://nestjs.com/) Monorepo

[![CircleCI](https://circleci.com/gh/modernweb-pl/vue-nest-monorepo/tree/master.svg?style=svg)](https://circleci.com/gh/modernweb-pl/workflows/vue-nest-monorepo/tree/master)


## Docker support

Repository includes Docker support for building and pushing images to GitHub Packages. Follow the steps below to build and push the Docker images.

### Prerequisites

Ensure you have Docker installed and running on your machine. You will also need to [authenticate to the GitHub Packages](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry#authenticating-to-the-container-registry) to push the Docker images.

```bash
echo $GITHUB_TOKEN | docker login ghcr.io -u <your-github-username> --password-stdin
```

Adjust `docker.registry` and `homegae` fields in `package.json` which are used to properly name the images and link them to your GitHub repository in GitHub Packages:

```json
{
"homepage": "https://github.com/<your-github-username>/<your-repository-name>",
"docker": {
"registry": "ghcr.io/<your-github-username>/<your-repository-name>"
}
}
```

### Building the Docker Images

To build the Docker images locally, you can use the following command:

```bash
pnpm docker:build
```

### Pushing the Docker Images to GitHub Packages

Once the images are built, push them to GitHub Packages using the following command:

```bash
pnpm docker:push
```

### Docker Compose Setup

Repository also includes a `docker-compose.yml` file for easier multi-container setup and orchestration. Use Docker Compose to start the services locally by running:

```bash
docker-compose up
```

This will spin up all defined services and link containers as needed.
38 changes: 0 additions & 38 deletions apps/api/Dockerfile

This file was deleted.

2 changes: 2 additions & 0 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"start": "nest start",
"preview": "node ../../dist/api/main",
"build": "nest build",
"docker:build": "node ../../scripts/docker build api",
"docker:push": "node ../../scripts/docker push api",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
Expand Down
2 changes: 1 addition & 1 deletion apps/api/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es2017",
"outDir": "../../dist/api",
"outDir": "./dist",
"baseUrl": "./",
"incremental": true
}
Expand Down
39 changes: 0 additions & 39 deletions apps/web/Dockerfile

This file was deleted.

2 changes: 2 additions & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"preview": "vite build && vite preview --port 4173",
"build": "concurrently 'pnpm type-check' 'pnpm build-only'",
"build-only": "vite build",
"docker:build": "node ../../scripts/docker build web",
"docker:push": "node ../../scripts/docker push web",
"test": "vitest run --environment jsdom",
"test:watch": "vitest --environment jsdom",
"test:e2e": "start-server-and-test 'pnpm preview' http://localhost:4173/ 'cypress run --e2e'",
Expand Down
2 changes: 1 addition & 1 deletion apps/web/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { VitePWA } from 'vite-plugin-pwa';
// https://vitejs.dev/config/
export default defineConfig({
build: {
outDir: '../../dist/web',
outDir: './dist',
emptyOutDir: true,
},
server: {
Expand Down
24 changes: 16 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
version: '3.7'

services:
web:
build:
context: .
dockerfile: apps/web/Dockerfile
target: web
environment:
- API_URL=http://localhost:3000/api
- CONFIG_VARS=API_URL
- CONFIG_VARS=API_URL,DEMO_MODE
- API_URL=http://localhost:3000
- DEMO_MODE=true
ports:
- 8080:80
- "8080:80"
tty: true

api:
build:
context: .
dockerfile: apps/api/Dockerfile
target: api
environment:
- AUTH_SECRET=ThisIsNotASecretKeyJustForTesting
- MONGO_URL=mongodb://mongo/vue-nest-monorepo
- NODE_ENV=demo
ports:
- 3000:3000
- "3000:3000"
tty: true

mongo:
image: mongo:8
ports:
- "27017:27017"
volumes:
- .data/mongo:/var/lib/mysql
18 changes: 12 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
{
"name": "vue-nest-monorepo",
"private": true,
"repository": "git@github.com:modernweb-pl/vue-nest-monorepo.git",
"author": "ModernWeb <biuro@modernweb.pl>",
"repository": "git@github.com:modernweb-pl/vue-nest-monorepo.git",
"homepage": "https://github.com/modernweb-pl/vue-nest-monorepo",
"docker": {
"registry": "ghcr.io/modernweb-pl/vue-nest-monorepo"
},
"type": "module",
"packageManager": "pnpm@9.10.0",
"engineStrict": true,
"engines": {
Expand All @@ -12,13 +17,12 @@
"scripts": {
"dev": "pnpm -r --parallel dev",
"api": "pnpm -F @app/api",
"api:docker": "docker build . -t docker.pkg.github.com/modernweb-pl/vue-nest-monorepo/api -f apps/api/Dockerfile",
"api:docker:push": "docker push docker.pkg.github.com/modernweb-pl/vue-nest-monorepo/api",
"web": "pnpm -F @app/web",
"web:docker": "docker build . -t docker.pkg.github.com/modernweb-pl/vue-nest-monorepo/web -f apps/web/Dockerfile",
"web:docker:push": "docker push docker.pkg.github.com/modernweb-pl/vue-nest-monorepo/web",
"build": "pnpm -r --parallel build",
"clean": "rimraf --glob dist node_modules apps/*/node_modules",
"docker:build": "pnpm -r --stream docker:build",
"docker:push": "pnpm -r --stream docker:push",
"clean": "rimraf --glob apps/*/dist node_modules apps/*/node_modules",
"clean:build": "rimraf --glob apps/*/dist",
"format": "pnpm lint --fix && prettier --write **/*.{html,scss,json}",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx,.vue,.cjs,.mjs",
"test": "pnpm -r --parallel test",
Expand All @@ -34,10 +38,12 @@
"eslint": "^8.41.0",
"eslint-config-prettier": "^7.2.0",
"eslint-plugin-prettier": "^3.4.1",
"execa": "^9.4.0",
"lint-staged": "~10.0.10",
"prettier": "~2.0.5",
"rimraf": "^6.0.1",
"typescript": "^4.9.5",
"yargs": "^17.7.2",
"yorkie": "~2.0.0"
},
"gitHooks": {
Expand Down
Loading

0 comments on commit d450e73

Please sign in to comment.