-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(create-turbo): apply official-starter transform
- Loading branch information
1 parent
98d1cc1
commit ba3d4e6
Showing
90 changed files
with
6,917 additions
and
1,633 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module.exports = { | ||
root: true, | ||
// This tells ESLint to load the config from the package `eslint-config-custom` | ||
extends: ["custom"], | ||
settings: { | ||
next: { | ||
rootDir: ["apps/*/"], | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,70 @@ | ||
# hackarteris | ||
Projeto para o hackaton. | ||
# Turborepo Docker starter | ||
|
||
This is an official Docker starter Turborepo. | ||
|
||
## Using this example | ||
|
||
Run the following command: | ||
|
||
```sh | ||
npx create-turbo@latest -e with-docker | ||
``` | ||
|
||
## What's inside? | ||
|
||
This turborepo uses [Yarn](https://classic.yarnpkg.com/lang/en/) as a package manager. It includes the following packages/apps: | ||
|
||
### Apps and Packages | ||
|
||
- `web`: a [Next.js](https://nextjs.org/) app | ||
- `api`: an [Express](https://expressjs.com/) server | ||
- `ui`: ui: a React component library | ||
- `eslint-config-custom`: `eslint` configurations for client side applications (includes `eslint-config-next` and `eslint-config-prettier`) | ||
- `eslint-config-custom-server`: `eslint` configurations for server side applications (includes `eslint-config-next` and `eslint-config-prettier`) | ||
- `scripts`: Jest configurations | ||
- `logger`: Isomorphic logger (a small wrapper around console.log) | ||
- `tsconfig`: tsconfig.json;s used throughout the monorepo | ||
|
||
Each package/app is 100% [TypeScript](https://www.typescriptlang.org/). | ||
|
||
### Docker | ||
|
||
This repo is configured to be built with Docker, and Docker compose. To build all apps in this repo: | ||
|
||
``` | ||
# Create a network, which allows containers to communicate | ||
# with each other, by using their container name as a hostname | ||
docker network create app_network | ||
# Build prod using new BuildKit engine | ||
COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker-compose -f docker-compose.yml build | ||
# Start prod in detached mode | ||
docker-compose -f docker-compose.yml up -d | ||
``` | ||
|
||
Open http://localhost:3000. | ||
|
||
To shutdown all running containers: | ||
|
||
``` | ||
# Stop all running containers | ||
docker kill $(docker ps -q) && docker rm $(docker ps -a -q) | ||
``` | ||
|
||
### Remote Caching | ||
|
||
This example includes optional remote caching. In the Dockerfiles of the apps, uncomment the build arguments for `TURBO_TEAM` and `TURBO_TOKEN`. Then, pass these build arguments to your Docker build. | ||
|
||
You can test this behavior using a command like: | ||
|
||
`docker build -f apps/web/Dockerfile . --build-arg TURBO_TEAM=“your-team-name” --build-arg TURBO_TOKEN=“your-token“ --no-cache` | ||
|
||
### Utilities | ||
|
||
This Turborepo has some additional tools already setup for you: | ||
|
||
- [TypeScript](https://www.typescriptlang.org/) for static type checking | ||
- [ESLint](https://eslint.org/) for code linting | ||
- [Jest](https://jestjs.io) test runner for all things JavaScript | ||
- [Prettier](https://prettier.io) for code formatting |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
root: true, | ||
extends: ["custom-server"], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
FROM node:18-alpine AS base | ||
|
||
# The web Dockerfile is copy-pasted into our main docs at /docs/handbook/deploying-with-docker. | ||
# Make sure you update this Dockerfile, the Dockerfile in the web workspace and copy that over to Dockerfile in the docs. | ||
|
||
FROM base AS builder | ||
# 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 | ||
# Set working directory | ||
WORKDIR /app | ||
RUN yarn global add turbo | ||
COPY . . | ||
RUN turbo prune api --docker | ||
|
||
# Add lockfile and package.json's of isolated subworkspace | ||
FROM base AS installer | ||
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 | ||
|
||
# Uncomment and use build args to enable remote caching | ||
# ARG TURBO_TEAM | ||
# ENV TURBO_TEAM=$TURBO_TEAM | ||
|
||
# ARG TURBO_TOKEN | ||
# ENV TURBO_TOKEN=$TURBO_TOKEN | ||
|
||
RUN yarn turbo run build --filter=api... | ||
|
||
FROM base 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 . | ||
|
||
CMD node apps/api/dist/index.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"name": "api", | ||
"version": "0.0.0", | ||
"private": true, | ||
"scripts": { | ||
"build": "tsc", | ||
"clean": "rm -rf dist", | ||
"dev": "nodemon --exec \"node -r esbuild-register ./src/index.ts\" -e .ts", | ||
"lint": "tsc --noEmit && eslint \"src/**/*.ts*\"", | ||
"start": "node -r esbuild-register ./src/index.ts", | ||
"test": "jest --detectOpenHandles" | ||
}, | ||
"jest": { | ||
"preset": "jest-presets/jest/node" | ||
}, | ||
"dependencies": { | ||
"body-parser": "^1.19.0", | ||
"cors": "^2.8.5", | ||
"express": "^4.17.1", | ||
"logger": "*", | ||
"morgan": "^1.10.0" | ||
}, | ||
"devDependencies": { | ||
"@types/body-parser": "^1.19.0", | ||
"@types/cors": "^2.8.10", | ||
"@types/express": "^4.17.12", | ||
"@types/jest": "^26.0.22", | ||
"@types/morgan": "^1.9.2", | ||
"@types/node": "^15.12.2", | ||
"@types/supertest": "^2.0.11", | ||
"esbuild": "^0.14.38", | ||
"esbuild-register": "^3.3.2", | ||
"eslint": "^7.32.0", | ||
"eslint-config-custom-server": "*", | ||
"jest": "^26.6.3", | ||
"jest-presets": "*", | ||
"nodemon": "^2.0.15", | ||
"supertest": "^6.1.3", | ||
"tsconfig": "*", | ||
"typescript": "^4.5.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import supertest from "supertest"; | ||
import { createServer } from "../server"; | ||
|
||
describe("server", () => { | ||
it("health check returns 200", async () => { | ||
await supertest(createServer()) | ||
.get("/healthz") | ||
.expect(200) | ||
.then((res) => { | ||
expect(res.body.ok).toBe(true); | ||
}); | ||
}); | ||
|
||
it("message endpoint says hello", async () => { | ||
await supertest(createServer()) | ||
.get("/message/jared") | ||
.expect(200) | ||
.then((res) => { | ||
expect(res.body).toEqual({ message: "hello jared" }); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"include": [".", "../."] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { createServer } from "./server"; | ||
import { log } from "logger"; | ||
|
||
const port = process.env.PORT || 3001; | ||
const server = createServer(); | ||
|
||
server.listen(port, () => { | ||
log(`api running on ${port}`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { json, urlencoded } from "body-parser"; | ||
import express from "express"; | ||
import morgan from "morgan"; | ||
import cors from "cors"; | ||
|
||
export const createServer = () => { | ||
const app = express(); | ||
app | ||
.disable("x-powered-by") | ||
.use(morgan("dev")) | ||
.use(urlencoded({ extended: true })) | ||
.use(json()) | ||
.use(cors()) | ||
.get("/message/:name", (req, res) => { | ||
return res.json({ message: `hello ${req.params.name}` }); | ||
}) | ||
.get("/healthz", (req, res) => { | ||
return res.json({ ok: true }); | ||
}); | ||
|
||
return app; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"compilerOptions": { | ||
"lib": ["ES2015"], | ||
"module": "CommonJS", | ||
"outDir": "./dist", | ||
"rootDir": "./src" | ||
}, | ||
"exclude": ["node_modules"], | ||
"extends": "tsconfig/base.json", | ||
"include": ["src"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
root: true, | ||
extends: ["custom"], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
FROM node:18-alpine AS base | ||
|
||
# This Dockerfile is copy-pasted into our main docs at /docs/handbook/deploying-with-docker. | ||
# Make sure you update both files! | ||
|
||
FROM base AS builder | ||
# 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 | ||
# Set working directory | ||
WORKDIR /app | ||
RUN yarn global add turbo | ||
COPY . . | ||
RUN turbo prune web --docker | ||
|
||
# Add lockfile and package.json's of isolated subworkspace | ||
FROM base AS installer | ||
RUN apk add --no-cache libc6-compat | ||
RUN apk update | ||
WORKDIR /app | ||
|
||
# First install the 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 | ||
COPY --from=builder /app/out/full/ . | ||
COPY turbo.json turbo.json | ||
|
||
# Uncomment and use build args to enable remote caching | ||
# ARG TURBO_TEAM | ||
# ENV TURBO_TEAM=$TURBO_TEAM | ||
|
||
# ARG TURBO_TOKEN | ||
# ENV TURBO_TOKEN=$TURBO_TOKEN | ||
|
||
RUN yarn turbo run build --filter=web... | ||
|
||
FROM base AS runner | ||
WORKDIR /app | ||
|
||
# Don't run production as root | ||
RUN addgroup --system --gid 1001 nodejs | ||
RUN adduser --system --uid 1001 nextjs | ||
USER nextjs | ||
|
||
COPY --from=installer /app/apps/web/next.config.js . | ||
COPY --from=installer /app/apps/web/package.json . | ||
|
||
# Automatically leverage output traces to reduce image size | ||
# https://nextjs.org/docs/advanced-features/output-file-tracing | ||
COPY --from=installer --chown=nextjs:nodejs /app/apps/web/.next/standalone ./ | ||
COPY --from=installer --chown=nextjs:nodejs /app/apps/web/.next/static ./apps/web/.next/static | ||
COPY --from=installer --chown=nextjs:nodejs /app/apps/web/public ./apps/web/public | ||
|
||
CMD node apps/web/server.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const path = require("path"); | ||
|
||
module.exports = { | ||
reactStrictMode: true, | ||
transpilePackages: ["ui"], | ||
output: "standalone", | ||
experimental: { | ||
outputFileTracingRoot: path.join(__dirname, "../../"), | ||
}, | ||
}; |
Oops, something went wrong.