πŸ›³ BE TIL Day 35 0429

JBΒ·2022λ…„ 4μ›” 29일
0

Backend02 Deploy

λͺ©λ‘ 보기
1/5
post-thumbnail

⬇️ Main Note
https://docs.google.com/document/d/19oDcieEkuX7xas-_Bai88iRlUeLBy-oaRVnXr9b-YSo/edit


πŸ›³ Deploy Sequence

  1. GCP -> Create instance
    Region : Seoul
    Boot disk β†’ ubuntu 20.04 // Balanced persistent disk //30

  2. Click SSH(Secure Shell) - Terminal of new computer
    This terminal is from the computer that we borrowed from GCP

  3. Clone the file link into 'SSH'

  4. Inside .env file, put important keys that shouldn't be uploaded to git hub.

  5. Edit docker.yaml files (create docker.yaml file for all dev, prod, and stage)

  6. git commit and clone in SSH =>
    docker-compose -f docker-compose.prod.yaml build

πŸ‹ docker-compose.yaml file


version: '3.7'

services:
  my-backend:
    build:
      context: .
      dockerfile: Dockerfile
    // volumes:
    //  - ./src:/myfolder/src 
    // volumesλŠ” λ°°ν¬νŒŒμΌμ—μ„œλŠ” μ£Όμ„μ²˜λ¦¬ (κ°‘μžκΈ° μœ μ € μ‚¬μš©μ€‘μΈλ° refresh되면 μ•ˆλ¨)
    env_file:
      - ./.env 
      // docker-compose.dev.yaml
      - ./.env.dev
      // docker-compose.prod.yaml
      - ./.env.prod
      // docker-compose.stage.yaml
      - ./.env.stage
      
    ports:
      - 3000:3000

  my-database:
    platform: linux/x86_64
    image: mysql:latest
    environment:
      MYSQL_DATABASE: 'mydocker02'
      MYSQL_ROOT_PASSWORD: 'root'
    ports:
      - 3306:3306

πŸ““ SSH Commands

πŸ‹ Creating Docker

sudo apt update
sudo apt upgrade

sudo apt install docker.io

mkdir -p ~/.docker/cli-plugins/

curl -SL https://github.com/docker/compose/releases/download/v2.2.3/docker-compose-linux-x86_64 -o ~/.docker/cli-plugins/docker-compose

chmod +x ~/.docker/cli-plugins/docker-compose

docker compose version // just for chekcing

πŸ‹ Docker setting

cat /etc/group => Adding user for security
sudo usermod -aG docker pjoobee
cat /etc/group => just for checking

πŸ‹ DB server on

git clone "//my repository address//"

Username & Password
➀ username : j00b33
➀ password : personal access token from git hub

vi .env.prod --> i :to get inside input mode
➀ Then copy the source code inside .env.prod file
➀ Enter 'esc' and type :wq
➀ Do the same thing for .env.dev and .env.stage file

πŸ‹ Docker Compose

docker compose -f docker-compose.prod.yaml build
docker compose -f docker-compose.prod.yaml up

If you want the docker to be composed on the background, add -d option=>
docker compose -f docker-compose.prod.yaml up -d


πŸ”₯ Firewall

After deploying, copy External IP Address
➀ 34.64.33.115:3000/graphql

But this link won't work since there is a firewall.
To solve this problem, I should..
➀ 1. make a sticker
➀ 2. attach the sticker to the computer that I want to destroy the firewall.

Particualr port that I selected will only work since stickers aren't attached to all the ports.

βœ”οΈ Create Firewall Rules

Source : Starting point(the part whre the access request is made)
Destination : The computer that docker-compose up is done, is becoming the destination.
Source IP Range : 0.0.0.0/0
➀ Everyone in the world is able to access to this port

TCP: 3000 (The port number that I'm going to open)
TCP Communication : Includes the logic that checks whether the receivng is well-done while communication with each other.
➀ High communication accuracy
UDP : Don't care whethere the receiving is well-done, but UDP keep sends the data
➀ Fast but communicatoin accuracy is quite low


profile
두비두λ°₯λ°₯

0개의 λŒ“κΈ€