Skip to content

Commit 17982d8

Browse files
feat(docker): web, backend-node
1 parent 7c05650 commit 17982d8

File tree

15 files changed

+211
-13
lines changed

15 files changed

+211
-13
lines changed

README.md

+47-5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ The main purpose of this repository is to provide a scalable "batteries included
2626
- **Includes CI**
2727
CI is integral part of any project. This starterkit includes `Github Actions` by default. PR's for integration with any other providers are welcome 🙌
2828

29+
- **Docker Support**
30+
You can also use docker to develop and run your applications
31+
2932
- **Testing Focused**
3033
This project uses [Jest](https://jestjs.io/) for testing framework and comes with sample tests which are easy to extend
3134

@@ -167,25 +170,64 @@ yarn
167170

168171
<i>To install dependencies for `web` and `backend` automatically, a postinstall script has been added in the main `package.json`</i>
169172

173+
**Running web**
174+
175+
- Docker (recommended)
176+
177+
```
178+
$ cd web
179+
$ yarn dev
180+
```
181+
182+
Once you're done working, use `yarn dev:down` command to stop the docker containers.
183+
184+
- Locally
185+
186+
```
187+
$ cd web
188+
$ yarn start:web
189+
```
190+
170191
**Running backend**
171192

193+
- Docker (recommended)
194+
172195
```
173-
yarn start:backend
196+
$ cd backend
197+
$ yarn dev
174198
```
175199

176-
<i>Make sure to use your own `DATABASE_URL` and not the default as provided in `.env.template` when developing your own project, as the demo database might be changed/deleted anytime</i>
200+
Once the container starts, you'll be inside the backend image. Now, simply migrate the db (only first time) and start the development server.
177201

178-
**Running web**
202+
```
203+
$ yarn migrate
204+
$ yarn start
205+
```
206+
207+
Once you're done working, exit out from the container and use `yarn dev:down` command to stop the docker containers.
208+
209+
- Locally
210+
211+
```
212+
$ cd backend
213+
$ yarn start
214+
```
215+
216+
_Note: When running locally, you'll be required to run your own instance of postgres._
217+
218+
**Running backend-go**
219+
220+
If you don't have [`make`](https://en.wikipedia.org/wiki/Make_(software)) installed, commands are available in `Makefile`.
179221

180222
```
181-
yarn start:web
223+
$ cd backend-go
224+
$ make dev
182225
```
183226

184227
<i>
185228
Feel free to open a new issue if you're facing any problem 🙋
186229
</i>
187230

188-
189231
**Codegen**
190232

191233
This starterkit uses [graphql-code-generator](https://github.com/dotansimha/graphql-code-generator) to codegen lot of things like TypeScript types, React Apollo hooks and queries, GraphQL Schema AST etc.

backend/.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/node_modules

backend/.env.template

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Default environment variables for backend
22
NODE_ENV=development | test | production
3-
DATABASE_URL=postgres://mjyjycebwtvykx:db2bd984b4ca9cdbcf23f6a504923e13564c7d91e766f4e2cc0b6475a8128f10@ec2-63-34-97-163.eu-west-1.compute.amazonaws.com:5432/dd6maefvg27ehd
3+
DATABASE_URL=postgres://user:password@db:5432/database

backend/Dockerfile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Ref: https://dev.to/karanpratapsingh/dockerize-node-application-222k
2+
FROM node:14.18-alpine
3+
WORKDIR /app
4+
COPY . .
5+
RUN yarn install
6+
EXPOSE 4000
7+
CMD tail -f /dev/null

backend/docker-compose.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
version: "3.8"
2+
3+
services:
4+
backend-node:
5+
container_name: backend-node
6+
image: backend-node
7+
build:
8+
context: .
9+
volumes:
10+
- .:/app
11+
- dependencies:/app/node_modules
12+
env_file:
13+
- .env
14+
ports:
15+
- 4000:4000
16+
depends_on:
17+
- db
18+
19+
db:
20+
image: postgres:12
21+
container_name: db
22+
environment:
23+
- POSTGRES_USER=user
24+
- POSTGRES_PASSWORD=password
25+
- POSTGRES_DB=database
26+
ports:
27+
- 5432:5432
28+
volumes:
29+
- postgres:/var/lib/postgresql/data
30+
31+
volumes:
32+
dependencies:
33+
postgres:

backend/package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@
1818
"url": "https://github.com/karanpratapsingh/fullstack-starterkit/issues"
1919
},
2020
"scripts": {
21+
"dev": "docker compose up -d && yarn dev:exec",
22+
"dev:exec": "docker exec -it backend-node /bin/sh",
23+
"dev:down": "docker compose down",
2124
"start": "yarn build --watch --hot",
2225
"test": "yarn jest --passWithNoTests --detectOpenHandles --verbose",
23-
"build": "webpack --color --progress",
26+
"build": "webpack --color",
2427
"build:clean": "rm -rf build && yarn build",
2528
"generate:graphql": "yarn workspace @project-backend/graphql run generate",
2629
"generate:prisma": "yarn workspace @project-backend/db run generate",
30+
"migrate": "yarn workspace @project-backend/db run migrate",
2731
"postinstall": "yarn generate:graphql && yarn generate:prisma"
2832
},
2933
"dependencies": {
@@ -38,6 +42,7 @@
3842
"typescript": "4.3.2"
3943
},
4044
"devDependencies": {
45+
"@types/jest": "^27.0.2",
4146
"chalk": "4.1.1",
4247
"dotenv-webpack": "7.0.3",
4348
"esbuild-loader": "2.13.1",

backend/packages/db/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
"generate": "yarn prisma generate --schema=./prisma/schema.prisma",
2222
"introspect": "yarn prisma introspect --schema=./prisma/schema.prisma",
2323
"studio": "yarn prisma studio --schema=./prisma/schema.prisma",
24-
"migrate:save": "yarn prisma migrate save --schema=./prisma/schema.prisma",
25-
"migrate:up": "yarn prisma migrate up --schema=./prisma/schema.prisma"
24+
"migrate": "yarn prisma migrate dev --schema=./prisma/schema.prisma"
2625
},
2726
"dependencies": {
2827
"@prisma/client": "2.20.0",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
-- CreateTable
2+
CREATE TABLE "User" (
3+
"id" TEXT NOT NULL,
4+
"email" TEXT NOT NULL,
5+
"name" TEXT NOT NULL,
6+
7+
PRIMARY KEY ("id")
8+
);
9+
10+
-- CreateTable
11+
CREATE TABLE "Post" (
12+
"id" TEXT NOT NULL,
13+
"authorId" TEXT,
14+
"content" TEXT,
15+
"published" BOOLEAN NOT NULL DEFAULT false,
16+
"title" TEXT NOT NULL,
17+
18+
PRIMARY KEY ("id")
19+
);
20+
21+
-- CreateIndex
22+
CREATE UNIQUE INDEX "User.email_unique" ON "User"("email");
23+
24+
-- AddForeignKey
25+
ALTER TABLE "Post" ADD FOREIGN KEY ("authorId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Please do not edit this file manually
2+
# It should be added in your version-control system (i.e. Git)
3+
provider = "postgresql"

backend/yarn.lock

+54
Original file line numberDiff line numberDiff line change
@@ -1563,6 +1563,17 @@
15631563
"@types/yargs" "^16.0.0"
15641564
chalk "^4.0.0"
15651565

1566+
"@jest/types@^27.2.5":
1567+
version "27.2.5"
1568+
resolved "https://registry.yarnpkg.com/@jest/types/-/types-27.2.5.tgz#420765c052605e75686982d24b061b4cbba22132"
1569+
integrity sha512-nmuM4VuDtCZcY+eTpw+0nvstwReMsjPoj7ZR80/BbixulhLaiX+fbv8oeLW8WZlJMcsGQsTmMKT/iTZu1Uy/lQ==
1570+
dependencies:
1571+
"@types/istanbul-lib-coverage" "^2.0.0"
1572+
"@types/istanbul-reports" "^3.0.0"
1573+
"@types/node" "*"
1574+
"@types/yargs" "^16.0.0"
1575+
chalk "^4.0.0"
1576+
15661577
"@josephg/resolvable@^1.0.0":
15671578
version "1.0.1"
15681579
resolved "https://registry.yarnpkg.com/@josephg/resolvable/-/resolvable-1.0.1.tgz#69bc4db754d79e1a2f17a650d3466e038d94a5eb"
@@ -1921,6 +1932,14 @@
19211932
dependencies:
19221933
"@types/istanbul-lib-report" "*"
19231934

1935+
"@types/jest@^27.0.2":
1936+
version "27.0.2"
1937+
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-27.0.2.tgz#ac383c4d4aaddd29bbf2b916d8d105c304a5fcd7"
1938+
integrity sha512-4dRxkS/AFX0c5XW6IPMNOydLn2tEhNhJV7DnYK+0bjoJZ+QTmfucBlihX7aoEsh/ocYtkLC73UbnBXBXIxsULA==
1939+
dependencies:
1940+
jest-diff "^27.0.0"
1941+
pretty-format "^27.0.0"
1942+
19241943
"@types/js-yaml@^4.0.0":
19251944
version "4.0.1"
19261945
resolved "https://registry.yarnpkg.com/@types/js-yaml/-/js-yaml-4.0.1.tgz#5544730b65a480b18ace6b6ce914e519cec2d43b"
@@ -2336,6 +2355,11 @@ ansi-regex@^5.0.0:
23362355
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.0.tgz#388539f55179bf39339c81af30a654d69f87cb75"
23372356
integrity sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==
23382357

2358+
ansi-regex@^5.0.1:
2359+
version "5.0.1"
2360+
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304"
2361+
integrity sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==
2362+
23392363
ansi-styles@^2.2.1:
23402364
version "2.2.1"
23412365
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe"
@@ -3529,6 +3553,11 @@ diff-sequences@^27.0.1:
35293553
resolved "https://registry.yarnpkg.com/diff-sequences/-/diff-sequences-27.0.1.tgz#9c9801d52ed5f576ff0a20e3022a13ee6e297e7c"
35303554
integrity sha512-XPLijkfJUh/PIBnfkcSHgvD6tlYixmcMAn3osTk6jt+H0v/mgURto1XUiD9DKuGX5NDoVS6dSlA23gd9FUaCFg==
35313555

3556+
diff-sequences@^27.0.6:
3557+
version "27.0.6"
3558+
resolved "https://registry.yarnpkg.com/diff-sequences/-/diff-sequences-27.0.6.tgz#3305cb2e55a033924054695cc66019fd7f8e5723"
3559+
integrity sha512-ag6wfpBFyNXZ0p8pcuIDS//D8H062ZQJ3fzYxjpmeKjnz8W4pekL3AI8VohmyZmsWW2PWaHgjsmqR6L13101VQ==
3560+
35323561
diff@^4.0.1:
35333562
version "4.0.2"
35343563
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
@@ -5071,6 +5100,16 @@ jest-config@^27.0.4:
50715100
micromatch "^4.0.4"
50725101
pretty-format "^27.0.2"
50735102

5103+
jest-diff@^27.0.0:
5104+
version "27.3.1"
5105+
resolved "https://registry.yarnpkg.com/jest-diff/-/jest-diff-27.3.1.tgz#d2775fea15411f5f5aeda2a5e02c2f36440f6d55"
5106+
integrity sha512-PCeuAH4AWUo2O5+ksW4pL9v5xJAcIKPUPfIhZBcG1RKv/0+dvaWTQK1Nrau8d67dp65fOqbeMdoil+6PedyEPQ==
5107+
dependencies:
5108+
chalk "^4.0.0"
5109+
diff-sequences "^27.0.6"
5110+
jest-get-type "^27.3.1"
5111+
pretty-format "^27.3.1"
5112+
50745113
jest-diff@^27.0.2:
50755114
version "27.0.2"
50765115
resolved "https://registry.yarnpkg.com/jest-diff/-/jest-diff-27.0.2.tgz#f315b87cee5dc134cf42c2708ab27375cc3f5a7e"
@@ -5129,6 +5168,11 @@ jest-get-type@^27.0.1:
51295168
resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-27.0.1.tgz#34951e2b08c8801eb28559d7eb732b04bbcf7815"
51305169
integrity sha512-9Tggo9zZbu0sHKebiAijyt1NM77Z0uO4tuWOxUCujAiSeXv30Vb5D4xVF4UR4YWNapcftj+PbByU54lKD7/xMg==
51315170

5171+
jest-get-type@^27.3.1:
5172+
version "27.3.1"
5173+
resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-27.3.1.tgz#a8a2b0a12b50169773099eee60a0e6dd11423eff"
5174+
integrity sha512-+Ilqi8hgHSAdhlQ3s12CAVNd8H96ZkQBfYoXmArzZnOfAtVAJEiPDBirjByEblvG/4LPJmkL+nBqPO3A1YJAEg==
5175+
51325176
jest-haste-map@^27.0.2:
51335177
version "27.0.2"
51345178
resolved "https://registry.yarnpkg.com/jest-haste-map/-/jest-haste-map-27.0.2.tgz#3f1819400c671237e48b4d4b76a80a0dbed7577f"
@@ -6417,6 +6461,16 @@ prepend-http@^2.0.0:
64176461
resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-2.0.0.tgz#e92434bfa5ea8c19f41cdfd401d741a3c819d897"
64186462
integrity sha1-6SQ0v6XqjBn0HN/UAddBo8gZ2Jc=
64196463

6464+
pretty-format@^27.0.0, pretty-format@^27.3.1:
6465+
version "27.3.1"
6466+
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-27.3.1.tgz#7e9486365ccdd4a502061fa761d3ab9ca1b78df5"
6467+
integrity sha512-DR/c+pvFc52nLimLROYjnXPtolawm+uWDxr4FjuLDLUn+ktWnSN851KoHwHzzqq6rfCOjkzN8FLgDrSub6UDuA==
6468+
dependencies:
6469+
"@jest/types" "^27.2.5"
6470+
ansi-regex "^5.0.1"
6471+
ansi-styles "^5.0.0"
6472+
react-is "^17.0.1"
6473+
64206474
pretty-format@^27.0.2:
64216475
version "27.0.2"
64226476
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-27.0.2.tgz#9283ff8c4f581b186b2d4da461617143dca478a4"

package.json

-4
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@
1717
"url": "https://github.com/karanpratapsingh/fullstack-starterkit/issues"
1818
},
1919
"scripts": {
20-
"start:web": "cd web && yarn start",
21-
"start:backend": "cd backend && yarn start",
22-
"build:web": "cd web && yarn build",
23-
"build:backend": "cd backend && yarn build",
2420
"lint": "yarn eslint --ext .js,.jsx,.ts,.tsx .",
2521
"lint:fix": "yarn prettier --write . && yarn lint --fix",
2622
"e2e": "yarn cypress open",

web/.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/node_modules

web/Dockerfile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Ref: https://dev.to/karanpratapsingh/dockerize-your-react-app-4j2e
2+
FROM node:14.18-alpine
3+
ENV NODE_ENV development
4+
ENV TSC_WATCHFILE UseFsEvents
5+
WORKDIR /app
6+
COPY package.json .
7+
COPY yarn.lock .
8+
RUN yarn install
9+
COPY . .
10+
EXPOSE 3000
11+
CMD tail -f /dev/null

web/docker-compose.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
version: "3.8"
2+
3+
services:
4+
web:
5+
container_name: web
6+
image: web
7+
restart: always
8+
build:
9+
context: .
10+
volumes:
11+
- .:/app
12+
- dependencies:/app/node_modules
13+
env_file:
14+
- .env
15+
ports:
16+
- 3000:3000
17+
18+
volumes:
19+
dependencies:

web/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
"url": "https://github.com/karanpratapsingh/fullstack-starterkit/issues"
1818
},
1919
"scripts": {
20+
"dev": "docker compose up",
21+
"dev:down": "docker compose down",
2022
"start": "craco start",
2123
"build": "craco build",
2224
"test": "yarn test:clean && craco test --watchAll=false",

0 commit comments

Comments
 (0)