Skip to content
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

Final #224

Closed
wants to merge 78 commits into from
Closed

Final #224

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
3a1b4ec
add gitignore
vanchung1995 Aug 14, 2024
5d55ae3
add structure feed and user
vanchung1995 Aug 14, 2024
f73735b
update docker
vanchung1995 Aug 14, 2024
0d014a8
add nginx docker
vanchung1995 Aug 14, 2024
b2d1aa4
add front-end docker
vanchung1995 Aug 14, 2024
f73b88d
update volumn aws
vanchung1995 Aug 14, 2024
e36fb26
update front-end docker
vanchung1995 Aug 14, 2024
b4d3be5
Update Dockerfile
vanchung1995 Aug 15, 2024
6fac126
Update Dockerfile
vanchung1995 Aug 15, 2024
6750099
Update Dockerfile
vanchung1995 Aug 15, 2024
6ed0dbf
Update Dockerfile
vanchung1995 Aug 15, 2024
e48ca7f
Update server.ts
vanchung1995 Aug 15, 2024
1dada4a
Update server.ts
vanchung1995 Aug 15, 2024
fd6d9c3
Update docker-compose.yml
vanchung1995 Aug 15, 2024
f4de0c8
Update nginx.conf
vanchung1995 Aug 15, 2024
b587716
Update docker-compose.yml
vanchung1995 Aug 15, 2024
73f9627
Update docker-compose.yml
vanchung1995 Aug 15, 2024
7eed23d
update docker
vanchung1995 Aug 15, 2024
996c7b1
Create app.config.json
vanchung1995 Aug 16, 2024
4553580
Create AppConfig.d.ts
vanchung1995 Aug 16, 2024
7239497
Create AppConfigService.ts
vanchung1995 Aug 16, 2024
fb08b85
Update app.module.ts
vanchung1995 Aug 16, 2024
ee4d862
Update api.service.ts
vanchung1995 Aug 16, 2024
cee1cc0
Create circleci config.yml
vanchung1995 Aug 16, 2024
6b31ea8
Create config.yml
vanchung1995 Aug 16, 2024
0717692
Delete .circleci directory
vanchung1995 Aug 16, 2024
2d0bf94
Update config.yml
vanchung1995 Aug 16, 2024
abeb26a
Update config.yml
vanchung1995 Aug 16, 2024
554a750
Update docker-compose.yml
vanchung1995 Aug 16, 2024
b94860e
Updated config.yml
vanchung1995 Aug 16, 2024
d0d270d
Updated config.yml
vanchung1995 Aug 16, 2024
19c793d
Create env-configmap.yaml
vanchung1995 Aug 19, 2024
720de53
Create env-secret.yaml
vanchung1995 Aug 19, 2024
389f1e5
Create aws-secret.yaml
vanchung1995 Aug 19, 2024
27d5b56
Create backend-feed-deployment.yaml
vanchung1995 Aug 19, 2024
bf8b64e
Create backend-user-deployment.yaml
vanchung1995 Aug 19, 2024
4724326
Create reverse-proxy-deployment.yaml
vanchung1995 Aug 19, 2024
49324f4
Create frontend-deployment.yaml
vanchung1995 Aug 19, 2024
7356ff0
Create backend-feed-service.yaml
vanchung1995 Aug 19, 2024
b5121b3
Create backend-user-service.yaml
vanchung1995 Aug 19, 2024
6995f75
Create reverse-proxy-service.yaml
vanchung1995 Aug 19, 2024
66ec562
Create frontend-service.yaml
vanchung1995 Aug 19, 2024
8bd3528
Update backend-feed-deployment.yaml
vanchung1995 Aug 19, 2024
30e8ae4
Update backend-user-deployment.yaml
vanchung1995 Aug 19, 2024
487e79d
Update frontend-deployment.yaml
vanchung1995 Aug 19, 2024
87bdee1
Update backend-user-deployment.yaml
vanchung1995 Aug 19, 2024
98ce8a6
Update reverse-proxy-deployment.yaml
vanchung1995 Aug 19, 2024
5c3deb3
Update backend-feed-service.yaml
vanchung1995 Aug 19, 2024
c2fc498
Update backend-user-service.yaml
vanchung1995 Aug 19, 2024
5560d60
Update frontend-service.yaml
vanchung1995 Aug 19, 2024
6e91d49
Update reverse-proxy-service.yaml
vanchung1995 Aug 19, 2024
a0a004b
Update frontend-service.yaml
vanchung1995 Aug 19, 2024
ea4794a
Update env-configmap.yaml
vanchung1995 Aug 20, 2024
efa521e
Update env-secret.yaml
vanchung1995 Aug 20, 2024
782f860
Update aws-secret.yaml
vanchung1995 Aug 20, 2024
27f5a29
Update backend-feed-deployment.yaml
vanchung1995 Aug 20, 2024
cc04313
Update backend-user-deployment.yaml
vanchung1995 Aug 20, 2024
a218fd7
Update backend-feed-service.yaml
vanchung1995 Aug 20, 2024
a628dd8
Update backend-user-service.yaml
vanchung1995 Aug 20, 2024
15e1a56
Update frontend-service.yaml
vanchung1995 Aug 20, 2024
c376f6a
Update frontend-service.yaml
vanchung1995 Aug 20, 2024
02a9d2c
Update reverse-proxy-service.yaml
vanchung1995 Aug 20, 2024
41b9822
Update backend-feed-service.yaml
vanchung1995 Aug 20, 2024
aec125c
Update backend-user-service.yaml
vanchung1995 Aug 20, 2024
4b3f0e4
Update app.config.json
vanchung1995 Aug 20, 2024
c67f6e9
Update frontend-service.yaml [ci skip]
vanchung1995 Aug 21, 2024
cf170d4
Update reverse-proxy-service.yaml [ci skip]
vanchung1995 Aug 21, 2024
bf9bc8c
Create commands.txt [ci skip]
vanchung1995 Aug 21, 2024
d15784b
Update backend-feed-deployment.yaml [ci skip]
vanchung1995 Aug 21, 2024
49c4cc1
Delete eks/commands.txt [ci skip]
vanchung1995 Aug 21, 2024
f26d045
Create commands.sh [ci skip]
vanchung1995 Aug 21, 2024
e953587
Update docker-compose.yml [ci skip]
vanchung1995 Aug 21, 2024
51e5d6d
Update frontend-deployment.yaml [skip ci]
vanchung1995 Aug 21, 2024
35599be
Update commands.sh [skip ci]
vanchung1995 Aug 21, 2024
e84853f
Update frontend-deployment.yaml [ci skip]
vanchung1995 Aug 21, 2024
0669cfd
Update frontend-deployment.yaml [ci skip]
vanchung1995 Aug 21, 2024
84cbedc
Update commands.sh [ci skip]
vanchung1995 Aug 21, 2024
c84d9fb
Add screenshot [ci skip]
vanchung1995 Aug 21, 2024
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 .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
version: 2.1

jobs:
build: # job name
docker: # executor type
- image: cimg/base:current # Docker image that installs Docker and has Git,
working_directory: ~/app
steps:
- checkout
- setup_remote_docker:
version: 20.10.14
- run:
name: Install dependencies
command: echo "No need to install anything. \n Just build and push the Docker image."
- run:
name: Build and push Docker image
command: |
echo "Inside the Build and push Docker image step"

docker --version # print the version for logging
docker-compose --version

docker-compose build --no-cache --progress plain frontend
docker-compose build --no-cache --progress plain reverseproxy
docker-compose build --no-cache --progress plain feed-api
docker-compose build --no-cache --progress plain user-api

echo "All images"
docker images

echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin

docker-compose push frontend
docker-compose push reverseproxy
docker-compose push feed-api
docker-compose push user-api
workflows:
build-workflow: # This is the name of the workflow, feel free to change it to better match your workflow.
# Inside the workflow, you define the jobs you want to run.
jobs:
- build
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ venv/
.elasticbeanstalk/*
!.elasticbeanstalk/*.cfg.yml
!.elasticbeanstalk/*.global.yml
set_env.sh
106 changes: 106 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
version: '3'

services:
postgres:
image: postgres:13
container_name: postgres
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: mypassword
POSTGRES_DB: postgres
volumes:
- postgres-db-volume:/var/lib/postgresql/data
healthcheck:
interval: 10s
retries: 5
start_period: 5s
restart: unless-stopped
ports:
- 5432:5432

frontend:
image: iamnarutohokage1995/udagram-frontend
container_name: udagram-frontend
build:
context: ./udagram-frontend
volumes:
- app.config.json:/usr/share/nginx/html/assets/app.config.json
ports:
- 8100:80
restart: unless-stopped

api:
image: iamnarutohokage1995/udagram-api
container_name: udagram-api
build:
dockerfile: Dockerfile
context: ./udagram-api/
volumes:
- $HOME/.aws:/root/.aws
ports:
- 8888:8080
restart: unless-stopped
environment:
- POSTGRES_USERNAME=$POSTGRES_USERNAME
- POSTGRES_PASSWORD=$POSTGRES_PASSWORD
- POSTGRES_HOST=$POSTGRES_HOST
- POSTGRES_DB=$POSTGRES_DB
- AWS_BUCKET=$AWS_BUCKET
- AWS_REGION=$AWS_REGION
- AWS_PROFILE=$AWS_PROFILE
- JWT_SECRET=$JWT_SECRET
- URL=$URL

user-api:
image: iamnarutohokage1995/udagram-api-user
container_name: udagram-api-user
build:
context: ./udagram-api-user
restart: unless-stopped
environment:
- POSTGRES_USERNAME=$POSTGRES_USERNAME
- POSTGRES_PASSWORD=$POSTGRES_PASSWORD
- POSTGRES_HOST=$POSTGRES_HOST
- POSTGRES_DB=$POSTGRES_DB
- AWS_BUCKET=$AWS_BUCKET
- AWS_REGION=$AWS_REGION
- AWS_PROFILE=$AWS_PROFILE
- JWT_SECRET=$JWT_SECRET
- URL=$URL

feed-api:
image: iamnarutohokage1995/udagram-api-feed
container_name: udagram-api-feed
build:
context: ./udagram-api-feed
volumes:
- $HOME/.aws:/root/.aws
restart: unless-stopped
environment:
- POSTGRES_USERNAME=$POSTGRES_USERNAME
- POSTGRES_PASSWORD=$POSTGRES_PASSWORD
- POSTGRES_HOST=$POSTGRES_HOST
- POSTGRES_DB=$POSTGRES_DB
- AWS_BUCKET=$AWS_BUCKET
- AWS_REGION=$AWS_REGION
- AWS_PROFILE=$AWS_PROFILE
- JWT_SECRET=$JWT_SECRET
- URL=$URL

reverseproxy:
image: iamnarutohokage1995/reverseproxy
container_name: reverseproxy
build:
context: ./udagram-reverseproxy
ports:
- 8080:8080
restart: always
depends_on:
- user-api
- feed-api
networks:
default:
driver: bridge

volumes:
postgres-db-volume:
9 changes: 9 additions & 0 deletions eks/aws-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v1
kind: Secret
metadata:
name: aws-secret
type: Opaque
data:
AWS_ACCESS_KEY_ID: <base64 encode access key>
AWS_SECRET_ACCESS_KEY: <base64 encode secret key>

76 changes: 76 additions & 0 deletions eks/backend-feed-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: feed-api
labels:
app: feed-api
spec:
replicas: 2
selector:
matchLabels:
app: feed-api
template:
metadata:
labels:
app: feed-api
spec:
containers:
- name: feed-api
image: iamnarutohokage1995/udagram-api-feed
ports:
- containerPort: 8080
volumeMounts:
- name: aws-credentials
mountPath: /root/.aws/credentials
subPath: credentials
env:
- name: AWS_BUCKET
valueFrom:
configMapKeyRef:
name: env-config
key: AWS_BUCKET
- name: AWS_REGION
valueFrom:
configMapKeyRef:
name: env-config
key: AWS_REGION
- name: URL
valueFrom:
configMapKeyRef:
name: env-config
key: URL
- name: POSTGRES_USERNAME
valueFrom:
secretKeyRef:
name: env-secret
key: POSTGRES_USERNAME
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: env-secret
key: POSTGRES_PASSWORD
- name: POSTGRES_HOST
valueFrom:
secretKeyRef:
name: env-secret
key: POSTGRES_HOST
- name: POSTGRES_DB
valueFrom:
secretKeyRef:
name: env-secret
key: POSTGRES_DB
- name: JWT_SECRET
valueFrom:
secretKeyRef:
name: env-secret
key: JWT_SECRET
- name: AWS_PROFILE
valueFrom:
secretKeyRef:
name: env-secret
key: AWS_PROFILE

volumes:
- name: aws-credentials
secret:
secretName: aws-secret
13 changes: 13 additions & 0 deletions eks/backend-feed-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: feed-api
labels:
app: feed-api
spec:
ports:
- port: 8080 # expose port
targetPort: 8080 # container port
protocol: TCP
selector:
app: feed-api
67 changes: 67 additions & 0 deletions eks/backend-user-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: user-api
labels:
app: user-api
spec:
replicas: 2
selector:
matchLabels:
app: user-api
template:
metadata:
labels:
app: user-api
spec:
containers:
- name: user-api
image: iamnarutohokage1995/udagram-api-user
ports:
- containerPort: 8080
env:
- name: AWS_BUCKET
valueFrom:
configMapKeyRef:
name: env-config
key: AWS_BUCKET
- name: AWS_REGION
valueFrom:
configMapKeyRef:
name: env-config
key: AWS_REGION
- name: URL
valueFrom:
configMapKeyRef:
name: env-config
key: URL
- name: POSTGRES_USERNAME
valueFrom:
secretKeyRef:
name: env-secret
key: POSTGRES_USERNAME
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: env-secret
key: POSTGRES_PASSWORD
- name: POSTGRES_HOST
valueFrom:
secretKeyRef:
name: env-secret
key: POSTGRES_HOST
- name: POSTGRES_DB
valueFrom:
secretKeyRef:
name: env-secret
key: POSTGRES_DB
- name: JWT_SECRET
valueFrom:
secretKeyRef:
name: env-secret
key: JWT_SECRET
- name: AWS_PROFILE
valueFrom:
secretKeyRef:
name: env-secret
key: AWS_PROFILE
13 changes: 13 additions & 0 deletions eks/backend-user-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: user-api
labels:
app: user-api
spec:
ports:
- port: 8080 # expose port
targetPort: 8080 # container port
protocol: TCP
selector:
app: user-api
49 changes: 49 additions & 0 deletions eks/commands.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# describe pods
kubectl get pods
kubectl describe pod [pod-name]
kubectl logs [pod-name]
kubectl exec --stdin --tty [pod-name] -- [/bin/bash | sh]

# describe services
kubectl get services
kubectl describe services

# describe hpa
kubectl autoscale deployment feed-api --cpu-percent=70 --min=3 --max=5
kubectl describe hpa

# describe deployments
kubectl get deployments

# apply all configmap and secret
kubectl apply -f env-secret.yaml
kubectl apply -f env-configmap.yaml

# apply all deployments and services
kubectl apply -f backend-feed-deployment.yaml
kubectl apply -f backend-user-deployment.yaml
kubectl apply -f backend-feed-service.yaml
kubectl apply -f backend-user-service.yaml

kubectl apply -f reverse-proxy-deployment.yaml
kubectl apply -f frontend-deployment.yaml

# expose services to external internet
kubectl expose deployment frontend --type=LoadBalancer --name=frontend
kubectl expose deployment reverse-proxy --type=LoadBalancer --name=reverse-proxy

# mount file to configmap
kubectl create configmap frontend-app-config --from-file=app.config.json

# mount file to secret
kubectl create secret generic aws-secret --from-file=$HOME/.aws/credentials

volumes:
- name: aws-credentials
secret:
secretName: aws-secret

volumeMounts:
- name: aws-credentials
mountPath: /root/.aws/credentials
subPath: credentials
8 changes: 8 additions & 0 deletions eks/env-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: env-config
data:
AWS_BUCKET: udagram-chungvv3-730554764003-bucket
AWS_REGION: us-east-1
URL: http://localhost:8080
Loading
Loading