Skip to content

Commit 0da1674

Browse files
Update deployment
1 parent 7e32c2c commit 0da1674

File tree

6 files changed

+87
-6
lines changed

6 files changed

+87
-6
lines changed

.github/workflows/build-docker-images.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,33 @@ on:
77
- master
88

99
env:
10+
QUESTIONS_IMAGE_NAME: peerprep-questions-service
1011
FRONTEND_IMAGE_NAME: peerprep-frontend
1112
NGINX_IMAGE_NAME: peerprep-nginx
1213

1314
jobs:
15+
build-questions-image:
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
19+
packages: write
20+
steps:
21+
- name: Check out Source
22+
uses: actions/checkout@v2
23+
- name: Log in to the Container Registry
24+
uses: docker/login-action@v1
25+
with:
26+
registry: ghcr.io
27+
username: peerprep
28+
password: ${{ secrets.GITHUB_TOKEN }}
29+
- name: Build and Push Docker Image
30+
uses: docker/build-push-action@v2
31+
with:
32+
context: .
33+
file: deployment/Dockerfile-questions
34+
push: true
35+
tags: ghcr.io/peerprep/${{ env.QUESTIONS_IMAGE_NAME }}:latest
36+
1437
build-frontend-image:
1538
runs-on: ubuntu-latest
1639
permissions:

deployment/Dockerfile-questions

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# To build a Docker image from this file, run from the root directory:
2+
# docker build -f deployment/Dockerfile-questions -t peerprep-questions-service .
3+
4+
# Intermediate image for building the Next app
5+
FROM node:18.17.1
6+
7+
# Environment variables
8+
ENV APP_ROOT /questions
9+
10+
# Copy source code into container
11+
RUN mkdir --parents $APP_ROOT
12+
WORKDIR $APP_ROOT
13+
COPY questions .
14+
15+
# Install dependencies
16+
RUN yarn install --frozen-lockfile
17+
18+
# Build app
19+
RUN yarn build
20+
21+
# Expose port
22+
EXPOSE 4000
23+
24+
# Final image for running the Express app
25+
CMD ["yarn", "start"]

deployment/docker-compose.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,40 @@
11
version: "3.8"
22

33
services:
4+
mongo:
5+
container_name: peerprep-mongo
6+
image: mongo
7+
restart: always
8+
volumes:
9+
- ./mongodb-data:/data/db
10+
logging:
11+
driver: journald
12+
networks:
13+
- peerprep-network
14+
expose:
15+
- "27017"
16+
17+
questions:
18+
image: ghcr.io/peerprep/peerprep-questions:latest
19+
container_name: peerprep-questions
20+
restart: always
21+
depends_on:
22+
- mongo
23+
networks:
24+
- peerprep-network
25+
logging:
26+
driver: journald
27+
expose:
28+
- "4000"
29+
environment:
30+
MONGODB_URL: "mongodb://peerprep-mongo:27017/questions"
31+
432
frontend:
533
image: ghcr.io/peerprep/peerprep-frontend:latest
634
container_name: peerprep-frontend
735
restart: always
36+
depends_on:
37+
- questions
838
networks:
939
- peerprep-network
1040
logging:

questions/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"description": "",
55
"main": "index.js",
66
"scripts": {
7-
"dev": "nodemon"
7+
"dev": "nodemon",
8+
"build": "tsc",
9+
"start": "node build/index.js"
810
},
911
"author": "",
1012
"license": "ISC",

questions/src/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import http from "http";
66
import mongoose from "mongoose";
77
import router from "./router";
88

9-
const MONGO_URL = "mongodb://localhost:27017/questions";
9+
const MONGO_URL =
10+
process.env.MONGODB_URL || "mongodb://localhost:27017/questions";
1011

1112
mongoose.Promise = Promise;
1213
mongoose.connect(MONGO_URL);
@@ -24,8 +25,8 @@ app.use(bodyParser.json());
2425

2526
const server = http.createServer(app);
2627

27-
server.listen(3000, () => {
28-
console.log("Server is listening on port 3000");
28+
server.listen(4000, () => {
29+
console.log("Server is listening on port 4000");
2930
});
3031

3132
app.use("/", router());

questions/tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"compilerOptions": {
33
"module": "NodeNext",
4-
"moduleResolution": "node",
4+
"moduleResolution": "NodeNext",
55
"baseUrl": "src",
6-
"outDir": "dist",
6+
"outDir": "build",
77
"sourceMap": true,
88
"noImplicitAny": true
99
},

0 commit comments

Comments
 (0)