Skip to content

Commit

Permalink
CI / CD (#71)
Browse files Browse the repository at this point in the history
* test staging

* test staging

* test

* Add configuration deploy app

* recover ports docker-compose.e2e.yml

* Expose port Gateway nginX to 7000:80

* Add deploy_branch_main.sh

* Expose port Gateway nginX to 7000:80

* delete logs useless folder

---------

Co-authored-by: Yilmaz Kadir <kadir-yilmaz_student2022@wilder.school>
  • Loading branch information
DavyR01 and MrRobo1 authored Jun 20, 2024
1 parent 132072c commit 0346e5c
Show file tree
Hide file tree
Showing 5 changed files with 190 additions and 0 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/staging-client.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# .github/workflows/staging-client.yml
name: Compile and push client image

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: ["staging"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

# login with Docker
- uses: docker/login-action@v1
name: Login to Docker Hub
with:
# generate some credentials from Dockerhub and store them into the repo secrets
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

# prepare buildx for docker
- uses: docker/setup-buildx-action@v1
name: Set up Docker Buildx

# build an push the newly created image
- uses: docker/build-push-action@v2
name: Build and push
with:
context: ./frontend
file: ./frontend/Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKER_HUB_CLIENT_IMAGE_NAME }}:latest
44 changes: 44 additions & 0 deletions .github/workflows/staging-server.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# .github/workflows/staging-server.yml
name: Compile and push server image

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: ["staging"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

# login with Docker
- uses: docker/login-action@v1
name: Login to Docker Hub
with:
# generate some credentials from Dockerhub and store them into the repo secrets
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

# prepare buildx for docker
- uses: docker/setup-buildx-action@v1
name: Set up Docker Buildx

# build an push the newly created image
- uses: docker/build-push-action@v2
name: Build and push
with:
context: ./backend
file: ./backend/Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKER_HUB_SERVER_IMAGE_NAME }}:latest
4 changes: 4 additions & 0 deletions deploy_branch_main.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
echo "PORT=$PORT"
git fetch origin && git reset --hard origin/main && git clean -f -d
GATEWAY_PORT=$PORT docker-compose -f docker-compose-prod.yml up --build -d
73 changes: 73 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
services:
backend:
image: wildrent9/staging-server
ports:
- 4000:4000
volumes:
- ./backend/src:/app/src
healthcheck:
test: 'curl --fail --request POST --header ''content-type: application/json'' --url ''http://localhost:4000'' --data ''{"query":"query { __typename }"}'' || exit 1'
interval: 5s
timeout: 5s
retries: 10
depends_on:
db:
condition: service_healthy

frontend:
image: wildrent9/staging-client
restart: always
environment:
- NODE_ENV=development
- CHOKIDAR_USEPOLLING=true
- WATCHPACK_POLLING=true
env_file: .env.dev
ports:
- 3000:3000
volumes:
- ./frontend/src:/app/src
depends_on:
backend:
condition: service_healthy

db:
image: postgres
restart: always
ports:
- "5434:5432"
environment:
POSTGRES_PASSWORD: wildrent
healthcheck:
test: ["CMD-SHELL", "pg_isready -d postgres -U postgres"]
interval: 10s
timeout: 5s
retries: 20
volumes:
- pgdata_new1:/var/lib/postgresql/data
imagesupload:
build: ./imagesupload
volumes:
- ./imagesupload/src:/app/src
- ./imagesupload/uploads:/app/uploads
ports:
- 8000:8000
nginx:
image: nginx:1.21.3
depends_on:
- backend
- frontend
restart: always
ports:
# - ${GATEWAY_PORT}:80
- 7000:80
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
- pgdata_new1:/pgdata_new1
- ./logs:/var/log/nginx
adminer:
image: adminer
ports:
- 8080:8080

volumes:
pgdata_new1:
25 changes: 25 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
events {}

http {
include mime.types;

server {
listen 80;

location /graphql {
proxy_pass http://backend:4000;
}

location ~ (/upload|/files) {
proxy_pass http://imagesupload:8000;
}

location /adminer {
proxy_pass http://adminer:8080;
}

location / {
proxy_pass http://frontend:3000;
}
}
}

0 comments on commit 0346e5c

Please sign in to comment.