Jieunny์˜ ๋ธ”๋กœ๊ทธ

S4) Unit 10. [Deploy]Github Action & Proxy ๋ณธ๋ฌธ

CodeStates/learning contents

S4) Unit 10. [Deploy]Github Action & Proxy

Jieunny 2023. 4. 4. 12:32

๐Ÿ“ฃ Github Action

๐Ÿญ. Github Actions ๋ž€?

โœ”๏ธ Github๊ฐ€ ๊ณต์‹์ ์œผ๋กœ ์ œ๊ณตํ•˜๋Š” ๋นŒ๋“œ, ํ…Œ์ŠคํŠธ ๋ฐ ๋ฐฐํฌ ํŒŒ์ดํ”„๋ผ์ธ์„ ์ž๋™ํ™”ํ•  ์ˆ˜ ์žˆ๋Š” CI/CD ํ”Œ๋žซํผ

โžฐ ๋ ˆํฌ์ง€ํ† ๋ฆฌ์—์„œ Pull Request ๋‚˜ push ๊ฐ™์€ ์ด๋ฒคํŠธ๋ฅผ ํŠธ๋ฆฌ๊ฑฐ๋กœ GitHub ์ž‘์—… ์›Œํฌํ”Œ๋กœ๋ฅผ ๊ตฌ์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค.

    ใ„ด ์›Œํฌํ”Œ๋กœ : ํ•˜๋‚˜ ์ด์ƒ์˜ ์ž‘์—…์ด ์‹คํ–‰๋˜๋Š” ์ž๋™ํ™” ํ”„๋กœ์„ธ์Šค๋กœ, ๊ฐ ์ž‘์—…์€ ์ž์ฒด ๊ฐ€์ƒ ๋จธ์‹  ๋˜๋Š” ์ปจํ…Œ์ด๋„ˆ ๋‚ด๋ถ€์—์„œ ์‹คํ–‰

    ใ„ด .yml (๋˜๋Š” .yaml ) ํŒŒ์ผ์— ์˜ํ•ด ๊ตฌ์„ฑ๋˜๋ฉฐ, ํ…Œ์ŠคํŠธ, ๋ฐฐํฌ ๋“ฑ ๊ธฐ๋Šฅ์— ๋”ฐ๋ผ ์—ฌ๋Ÿฌ๊ฐœ์˜ ์›Œํฌํ”Œ๋กœ๋„ ๋งŒ๋“ค ์ˆ˜ ์žˆ๊ณ  ์ƒ์„ฑ๋œ ์›Œํฌํ”Œ๋กœ๋Š” .github/workflows ๋””๋ ‰ํ† ๋ฆฌ ๋ฐ‘์— ์œ„์น˜ํ•œ๋‹ค.

โžฐ ๋น„๊ณต๊ฐœ ๋ ˆํฌ์ง€ํ† ๋ฆฌ์˜ ๊ฒฝ์šฐ Github Actions๊ฐ€ ์ž‘๋™ํ•  ๋•Œ์˜ ์šฉ๋Ÿ‰๊ณผ ์‹œ๊ฐ„์ด ์ œํ•œ๋˜์–ด์žˆ์œผ๋ฉฐ ๊ณต๊ฐœ ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋Š” ๋ฌด๋ฃŒ๋กœ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๋‹ค.

 

๐Ÿฎ. YAML(Yet Another Markup Language) ์ด๋ž€?

โœ”๏ธ ์‚ฌ๋žŒ์ด ์ฝ์„ ์ˆ˜ ์žˆ๋Š” ๋ฐ์ดํ„ฐ ์ง๋ ฌํ™” ์–ธ์–ด

โžฐ ํŒŒ์ผ๋กœ ์ž‘์„ฑ์‹œ ํ™•์žฅ์ž๋Š” .yaml ํ˜น์€ .yml ๋ฅผ ๊ฐ€์ง„๋‹ค.

 

๐Ÿฏ. JSON vs YAML

// YAML ํŒŒ์ผ

name: Bare Minimum Requirements
on: [push, pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Bare Minimum Requirements
        uses: actions/setup-node@v1
        with:
          node-version: '16'
      - run: npm install
      - run: npm test
// JSON ํŒŒ์ผ

{
  "squadName": "Super hero squad",
  "homeTown": "Metro City",
  "formed": 2016,
  "secretBase": "Super tower",
  "active": true,
  "members": [
    {
      "name": "Molecule Man",
      "age": 29,
      "secretIdentity": "Dan Jukes",
      "powers": [
        "Radiation resistance",
        "Turning tiny",
        "Radiation blast"
      ]
    }
  ]
}
  YAML JSON
๊ณตํ†ต์  - key-value ํ˜•ํƒœ๋กœ ์ž‘์„ฑ๋œ ํŒŒ์ผ
- ๊ณ„์ธต ๊ตฌ์กฐ๋ฅผ ๊ฐ€์ง„๋‹ค
์ฐจ์ด์  - "" ์—†์ด๋„ ๋ฌธ์ž์—ด ์ž‘์„ฑ์ด ๊ฐ€๋Šฅํ•˜๋‹ค.
- {} ํ˜•ํƒœ๋กœ ๊ฐ์‹ธ์ค„ ํ•„์š”๊ฐ€ ์—†๋‹ค.
- ์ฃผ์„์„ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค.
- JSON์˜ ์ƒ์œ„ ํ˜ธํ™˜ ๊ฒฉ์œผ๋กœ ๊ธฐ์กด json๋ฌธ์„œ๋ฅผ ๊ทธ๋Œ€๋กœ yaml๋กœ ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜ ์›ํ•˜๋Š” ๋ถ€๋ถ„๋งŒ ์ˆ˜์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.
- yaml์„ json์œผ๋กœ ๋ณ€ํ™˜ํ•ด ์‚ฌ์šฉํ•  ์ˆ˜๋„ ์žˆ๋‹ค.
- {} ํ˜•ํƒœ๋กœ ๊ฐ์‹ธ์ฃผ์–ด์•ผ ํ•œ๋‹ค.
- ์ฃผ์„์„ ์ž‘์„ฑํ•  ์ˆ˜ ์—†๋‹ค.

 

๐Ÿฐ. YAML ๋ฌธ๋ฒ•

1๏ธโƒฃ ์ฃผ์„ & ๋ฌธ์„œ์˜ ์‹œ์ž‘๊ณผ ๋

#์ด๋Ÿฐ ์‹์œผ๋กœ ์ฃผ์„์„ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

--- #๋ฌธ์„œ ์‹œ์ž‘

#์ด ์‚ฌ์ด์— ๋‚ด์šฉ์ด ๋“ค์–ด๊ฐ‘๋‹ˆ๋‹ค.

... #๋ฌธ์„œ ๋

 

2๏ธโƒฃ ๊ธฐ๋ณธ ํ‘œํ˜„

โžฐ key: value ์ด๋ฉฐ, : ๋‹ค์Œ์—๋Š” ๋ฌด์กฐ๊ฑด ๊ณต๋ฐฑ ๋ฌธ์ž๊ฐ€ ์™€์•ผํ•œ๋‹ค.

key: value

 

3๏ธโƒฃ ์ž๋ฃŒํ˜•

โžฐ int, string, boolean, ๋ฆฌ์ŠคํŠธ, ๋งคํ•‘์„ ์ง€์›ํ•œ๋‹ค.

#int(์ˆซ์ž)
int_type: 1

#string(๋ฌธ์ž์—ด)
string_type: "1"

#blooean(์ฐธ/๊ฑฐ์ง“)
boolean_true_type: true
boolean_false_type: false

#์ด์™ธ์— yes, no๋กœ ์ž‘์„ฑํ•˜๊ธฐ๋„ ํ•ฉ๋‹ˆ๋‹ค.
yaml_easy: yes
yaml_difficult: no

#๋ฆฌ์ŠคํŠธ(๋ฐฐ์—ด ํ˜•ํƒœ)
person:
  name: Chungsub Kim
  job: Developer
  skills: 
    - docker
    - kubernetes
  # JSON ํ˜•์‹์˜ "skill" : [docker, kubernetes]์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

 

4๏ธโƒฃ ๊ฐ์ฒด

โžฐ key ์ž‘์„ฑ ํ›„ ๋‘ ์นธ์„ ๋“ค์—ฌ์จ์„œ key-value ํ˜•ํƒœ๋กœ ์ž‘์„ฑ์„ ํ•ด์ฃผ๊ฑฐ๋‚˜, key๋ฅผ ์ž‘์„ฑ ํ›„ ์ค‘๊ด„ํ˜ธ({})๋กœ ํ•œ ๋ฒˆ ๋ฌถ๊ณ  key-value ํ˜•ํƒœ๋กœ ์ž‘์„ฑ

key: 
  key: value
  key: value

#๋˜๋Š” ์ด๋ ‡๊ฒŒ๋„ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค. ๊ฐ€๋…์„ฑ์„ ์œ„ํ•ด ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
key: {
  key: value,
  key: value
}

 

5๏ธโƒฃ Text

โžฐ ์ค„๋ฐ”๊ฟˆ ํ‘œํ˜„(|)๊ณผ ์ค„๋ฐ”๊ฟˆ ๋ฌด์‹œ ํ‘œํ˜„(>)

# |๋Š” ์ค„๋ฐ”๊ฟˆ ํ‘œํ˜„์ž…๋‹ˆ๋‹ค.
# JSON ํ˜•์‹์˜ "comment_line_break": "Hello codestates.\nIm kimcoding.\n"๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.
comment_line_break: |
  Hello codestates.
  Im kimcoding.

# >๋Š” ์ค„๋ฐ”๊ฟˆ ๋ฌด์‹œ ํ‘œํ˜„์ž…๋‹ˆ๋‹ค.
# JSON ํ˜•์‹์˜ "comment_single_line": "Hello world my first coding."๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.
comment_single_line: >
  Hello world
  my first coding.

 

6๏ธโƒฃ ๋ฌธ์ž์—ด ๋”ฐ์˜ดํ‘œ

โžฐ key-value ์Œ์—์„œ value์— :๊ฐ€ ๋“ค์–ด๊ฐ„ ๊ฒฝ์šฐ๋Š” ๋ฐ˜๋“œ์‹œ ๋”ฐ์˜ดํ‘œ๊ฐ€ ํ•„์š”ํ•˜๋‹ค.

# error๊ฐ€ ๋‚ฉ๋‹ˆ๋‹ค.
windows_drive: c:

# ์ด๋ ‡๊ฒŒ ์จ์•ผ ํ•ฉ๋‹ˆ๋‹ค.
windows_drive: "c:"
windows_drive: 'c:'

 

๐Ÿฑ. YAML ์‚ฌ์šฉ๋ฒ• ๋ฐ ์‹ค์ œ ์‚ฌ์šฉ ์‚ฌ๋ก€

โœ”๏ธ configure ํŒŒ์ผ ๋“ฑ ์„ค์ • ํŒŒ์ผ์— ์‚ฌ์šฉํ•˜๊ธฐ ์ข‹์€ ์–ธ์–ด

โžฐ spring boot, github action ๋“ฑ ๋‹ค์–‘ํ•œ CI/CD ํˆด์ด๋‚˜ ํ”„๋ ˆ์ž„์›Œํฌ์—์„œ ์‚ฌ์šฉ๋œ๋‹ค.

โžฐ YAML์„ ์‹ค์ œ๋กœ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋Š” ํ”„๋ ˆ์ž„์›Œํฌ : ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค


๐Ÿ“ฃ Proxy

๐Ÿญ. Proxy๋ž€?

โœ”๏ธ React ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ, ํ˜น์€ Webpack Dev Server์—์„œ ์ œ๊ณตํ•˜๋Š” CORS ์ •์ฑ…์„ ์šฐํšŒํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋Šฅ

โžฐ React ์•ฑ์—์„œ ๋ธŒ๋ผ์šฐ์ €๋ฅผ ํ†ตํ•ด API๋ฅผ ์š”์ฒญํ•  ๋•Œ, proxy๋ฅผ ํ†ตํ•ด ๋ฐฑ์—”๋“œ ์„œ๋ฒ„๋กœ ์š”์ฒญ์„ ์šฐํšŒํ•˜์—ฌ ๋ณด๋‚ธ๋‹ค => ๋ฐฑ์—”๋“œ ์„œ๋ฒ„๋Š” ์‘๋‹ต์„ React ์•ฑ์œผ๋กœ ๋ณด๋‚ด๊ณ , React ์•ฑ์€ ๋ฐ›์€ ์‘๋‹ต์„ ๋ฐฑ์—”๋“œ ์„œ๋ฒ„ ๋Œ€์‹  ๋ธŒ๋ผ์šฐ์ €์—๊ฒŒ ์ „๋‹ฌํ•œ๋‹ค(์ถœ์ฒ˜๊ฐ€ ๊ฐ™์•„์ง€๊ธฐ ๋•Œ๋ฌธ์— ๋ธŒ๋ผ์šฐ์ €๋Š” ์ด ์‚ฌ์‹ค์„ ๋ˆˆ์น˜ ์ฑ„์ง€ ๋ชปํ•˜๊ณ  ํ—ˆ์šฉํ•˜๊ฒŒ ๋œ๋‹ค)

 

๐Ÿญ. Proxy ์‚ฌ์šฉ๋ฒ•

1๏ธโƒฃ webpack dev server proxy ์—์„œ ์ œ๊ณตํ•˜๋Š” proxy ๊ธฐ๋Šฅ ์‚ฌ์šฉ

โžฐ ๋ธŒ๋ผ์šฐ์ € API๋ฅผ ์š”์ฒญํ•  ๋•Œ ๋ฐฑ์—”๋“œ ์„œ๋ฒ„์— ์ง์ ‘์ ์œผ๋กœ ์š”์ฒญ์„ ํ•˜์ง€ ์•Š๊ณ , ํ˜„์žฌ ๊ฐœ๋ฐœ์„œ๋ฒ„์˜ ์ฃผ์†Œ๋กœ ์šฐํšŒ ์š”์ฒญ์„ ํ•œ๋‹ค.

โžฐ ์›นํŒฉ ๊ฐœ๋ฐœ ์„œ๋ฒ„์—์„œ ํ•ด๋‹น ์š”์ฒญ์„ ๋ฐ›์•„ ๊ทธ๋Œ€๋กœ ๋ฐฑ์—”๋“œ ์„œ๋ฒ„๋กœ ์ „๋‹ฌํ•˜๊ณ , ๋ฐฑ์—”๋“œ ์„œ๋ฒ„์—์„œ ์‘๋‹ตํ•œ ๋‚ด์šฉ์„ ๋‹ค์‹œ ๋ธŒ๋ผ์šฐ์ €์ชฝ์œผ๋กœ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

โžฐ CRA๋กœ ๋งŒ๋“  ๋ฆฌ์•กํŠธ ํ”„๋กœ์ ํŠธ์—์„œ๋Š” package.json์˜ proxy๊ฐ’์„ ์„ค์ •ํ•˜์—ฌ ์ ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

...
"browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
	"proxy" : "์šฐํšŒํ•  API ์ฃผ์†Œ"
}
export async function getAllfetch() {

    const response = await fetch('์šฐํšŒํ•  api์ฃผ์†Œ/params');
    .then(() => {
			...
		})
}

export async function getAllfetch() {

    const response = await fetch('/params');
    .then(() => {
			...
		})
}

โžฐ ๊ธฐ์กด์˜ fetch, axios๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ›์•„์˜ค๋˜ ๋ถ€๋ถ„์—์„œ ๋„๋ฉ”์ธ ๋ถ€๋ถ„์„ ์ œ๊ฑฐํ•œ๋‹ค.

 

๐Ÿญ. React Proxy ์‚ฌ์šฉ๋ฒ•

1๏ธโƒฃ http-proxy-middleware ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์„ค์น˜

npm install http-proxy-middleware --save

 

2๏ธโƒฃ srcํŒŒ์ผ ์•ˆ์— setupProxy.js ํŒŒ์ผ์„ ์ƒ์„ฑํ•˜๊ณ  ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ํŒŒ์ผ์„ ๋ถˆ๋Ÿฌ์˜จ ํ›„ ์ž‘์„ฑํ•œ๋‹ค.

const { createProxyMiddleware } = require('http-proxy-middleware');

module.exports = function(app) {
  app.use(
    '/api', //proxy๊ฐ€ ํ•„์š”ํ•œ path prameter๋ฅผ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.
    createProxyMiddleware({
      target: 'http://localhost:5000', //ํƒ€๊ฒŸ์ด ๋˜๋Š” api url๋ฅผ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.
      changeOrigin: true, //๋Œ€์ƒ ์„œ๋ฒ„ ๊ตฌ์„ฑ์— ๋”ฐ๋ผ ํ˜ธ์ŠคํŠธ ํ—ค๋”๊ฐ€ ๋ณ€๊ฒฝ๋˜๋„๋ก ์„ค์ •ํ•˜๋Š” ๋ถ€๋ถ„์ž…๋‹ˆ๋‹ค.
    })
  );
};

 

3๏ธโƒฃ ๊ธฐ์กด์˜ fetch, ํ˜น์€ axios๋ฅผ ํ†ตํ•ด ์š”์ฒญํ•˜๋˜ ๋ถ€๋ถ„์—์„œ ๋„๋ฉ”์ธ ๋ถ€๋ถ„์„ ์ œ๊ฑฐํ•œ๋‹ค.

export async function getAllfetch() {

    const response = await fetch('์šฐํšŒํ•  api์ฃผ์†Œ/params');
    .then(() => {
			...
		})
}

export async function getAllfetch() {

    const response = await fetch('/params');
    .then(() => {
			...
		})
}