Skip to content

Docker support #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,44 @@ Learn more about the power of Turborepo:
- [Scoped Tasks](https://turborepo.org/docs/features/scopes)
- [Configuration Options](https://turborepo.org/docs/reference/configuration)
- [CLI Usage](https://turborepo.org/docs/reference/command-line-reference)

### Docker Support

If you want to deploy with docker there is a Dockerfile included to help with that
_Note: Dockerfile only works to build docker image to deploy and does not support local development_

#### How to build
Run this command to build a docker image where the {SCOPE_NAME} is the workspace you want to build
```shell
docker-compose up {SCOPE_NAME}
```

For example:
```shell
docker-compose up web
```
Brings up web app and
```shell
docker-compose up docs
```
Brings up docs app

if you want to add another app and build a docker image for it, you can just add a new service in docker-compose like
```yaml
newapp:
container_name: newapp
build:
args:
APP_SCOPE: "newapp"
context: .
dockerfile: ./docker/Dockerfile
restart: always
ports:
- "3003:80"
```

and run
```shell
docker-compose up newapp
```
to bring up newapp app
23 changes: 23 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: "3"

services:
web:
container_name: web
build:
args:
APP_SCOPE : "web"
context: .
dockerfile: ./docker/Dockerfile
restart: always
ports:
- "3000:80"
docs:
container_name: docs
build:
args:
APP_SCOPE: "docs"
context: .
dockerfile: ./docker/Dockerfile
restart: always
ports:
- "3001:80"
37 changes: 37 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM node:18-alpine AS base

FROM base AS builder
ARG APP_SCOPE
ENV APP_SCOPE ${APP_SCOPE}
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
RUN apk update
WORKDIR /app
RUN yarn global add turbo
COPY . .
RUN yarn turbo prune --scope=${APP_SCOPE} --docker

# Add lockfile and package.json's of isolated subworkspace
FROM base AS installer
ARG APP_SCOPE
ENV APP_SCOPE ${APP_SCOPE}
RUN apk add --no-cache libc6-compat
RUN apk update
WORKDIR /app
COPY .gitignore .gitignore
COPY --from=builder /app/out/json/ .
COPY --from=builder /app/out/yarn.lock ./yarn.lock
COPY --from=builder /app/out/full/ .
RUN yarn install
COPY turbo.json turbo.json
RUN yarn turbo run build --scope=${APP_SCOPE}

# production stage
FROM nginx:stable-alpine as production-stage
ARG APP_SCOPE
ENV APP_SCOPE ${APP_SCOPE}
COPY --from=installer /app/apps/${APP_SCOPE}/dist /usr/share/nginx/html
EXPOSE 80
STOPSIGNAL SIGTERM
CMD ["nginx", "-g", "daemon off;"]