[Github Action] Github Action์„ ์ด์šฉํ•ด์„œ EC2์— ์ž๋™๋ฐฐํฌํ•˜๊ธฐ (์ž‘์„ฑ์ค‘)

2023. 7. 29. 20:37ยท๐Ÿ“DevOps
๋ชฉ์ฐจ
  1. ํŒŒ์ดํ”„๋ผ์ธ
  2. ๋ฐฉ๋ฒ•
๋ฐ˜์‘ํ˜•

์›๋ž˜ ๋ฐฐํฌ ๋กœ์ง์€,

๊ฐœ๋ฐœ ๋ณ€๊ฒฝ ์‚ฌํ•ญ์ด main ๋ธŒ๋ Œ์น˜์— merge ๋˜๋ฉด ec2์— ์ ‘์†ํ•ด์„œ ํ•ด๋‹น ํ”„๋กœ์ ํŠธ์— ๋ธŒ๋ Œ์น˜๋ฅผ pull ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์—ˆ๋‹ค.

๊ทธ๋Ÿฐ๋ฐ Github Action์„ ์‚ฌ์šฉํ•ด์„œ ์œ„ ๊ณผ์ •์„ ์ž๋™ํ™”์‹œํ‚ฌ ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฒƒ์„ ์•Œ๊ฒŒ๋˜์–ด ์ ์šฉํ•ด๋ณด์•˜๋‹ค.

 


 

ํŒŒ์ดํ”„๋ผ์ธ

1. ๋กœ์ปฌ์ปดํ“จํ„ฐ์—์„œ main ๋ธŒ๋ Œ์น˜๋กœ push ํ•˜๋ฉด

2. Github Action ์‹คํ–‰

    1) ec2์— ์ ‘์†

    2) ์ž‘์„ฑ๋œ script ์‹คํ–‰

        - cloneํ•œ ํ”„๋กœ์ ํŠธ๋กœ ์ด๋™

        - ์ง€์ •ํ•œ ๋ธŒ๋ Œ์น˜๋ฅผ git pull

3. ๋ฐฐํฌ ์™„๋ฃŒ

 


 

๋ฐฉ๋ฒ•

1. Github Action ์ƒ์„ฑํ•˜๊ธฐ

Github > ์ ์šฉํ•  ํ”„๋กœ์ ํŠธ > Action

set up a workflow yourself  ํด๋ฆญ

 

.yml ํŒŒ์ผ ์ž‘์„ฑํ•˜๊ธฐ

name: main branch auto ci process script

on: # ์•„๋ž˜ job์„ ์‹คํ–‰์‹œํ‚ฌ action
  push:
    branches: [ main ]

jobs:
  deploy:
    name: deploy
    runs-on: ubuntu-latest # ์‹คํ–‰๋  ์ธ์Šคํ„ด์Šค OS์™€ ๋ฒ„์ „

    steps:
      - name: excuting remote ssh commands
        uses: appleboy/ssh-action@v0.1.9 # ssh ์ ‘์†ํ•˜๋Š” ์˜คํ”ˆ์†Œ์Šค
        with:
          host: ${{ secrets.REMOTE_IP }} # ec2 ์ธ์Šคํ„ด์Šค ip
          username: ${{ secrets.REMOTE_USER }} # ubuntu ์•„์ด๋””
          key: ${{ secrets.REMOTE_PRIVATE_KEY }} # ec2 ์ธ์Šคํ„ด์Šค pem key
          port: ${{ secrets.REMOTE_SSH_PORT }} # ์ ‘์†ํฌํŠธ๋ฒˆํ˜ธ (๋ณดํ†ต 22)
          script: | # ์‹คํ–‰๋  ์Šคํฌ๋ฆฝํŠธ
            cd /var/www/html/test-project
            git pull

Commit changes...

 

 

2. .yml ํŒŒ์ผ์—์„œ ์ž‘์„ฑํ•œ ์ž‘์—…์•”ํ˜ธ ๋ฐ ๋ณ€์ˆ˜ ์ƒ์„ฑํ•˜๊ธฐ

Github > ์ ์šฉํ•  ํ”„๋กœ์ ํŠธ > Settings > Secrets ans variables > Actions

New repository secret ํด๋ฆญ

 

์ƒ์„ฑํ•˜๊ธฐ

Add secret

๋ฐ˜์‘ํ˜•
์ €์ž‘์žํ‘œ์‹œ (์ƒˆ์ฐฝ์—ด๋ฆผ)

'๐Ÿ“DevOps' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[AWS] Job for nginx.service failed because the control process exited with error code. ์—๋Ÿฌ  (0) 2023.03.08
[AWS] ํƒ„๋ ฅ์  IP(Elastic IPs) ์‚ฌ์šฉํ•˜๊ธฐ  (0) 2023.02.26
[AWS] https ์ธ์ฆ ๋งŒ๋ฃŒ์‹œ ํ•ด๊ฒฐ๋ฐฉ๋ฒ•  (0) 2023.01.17
[AWS] mysql ์™ธ๋ถ€์ ‘๊ทผ ํ—ˆ์šฉํ•˜๊ธฐ  (0) 2022.07.11
[AWS] ์šฐ๋ถ„ํˆฌ์— ๋ผ๋ผ๋ฒจ ๊ฐœ๋ฐœํ™˜๊ฒฝ ๊ตฌ์ถ•ํ•˜๊ธฐ php7.4  (0) 2022.05.02
  1. ํŒŒ์ดํ”„๋ผ์ธ
  2. ๋ฐฉ๋ฒ•
'๐Ÿ“DevOps' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€
  • [AWS] Job for nginx.service failed because the control process exited with error code. ์—๋Ÿฌ
  • [AWS] ํƒ„๋ ฅ์  IP(Elastic IPs) ์‚ฌ์šฉํ•˜๊ธฐ
  • [AWS] https ์ธ์ฆ ๋งŒ๋ฃŒ์‹œ ํ•ด๊ฒฐ๋ฐฉ๋ฒ•
  • [AWS] mysql ์™ธ๋ถ€์ ‘๊ทผ ํ—ˆ์šฉํ•˜๊ธฐ
yujch
yujch
ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๊ณต๋ถ€ ๋ฉ”๋ชจ
    ๋ฐ˜์‘ํ˜•
  • yujch
    โœŽRepository
    yujch
  • ์ „์ฒด
    ์˜ค๋Š˜
    ์–ด์ œ
    • ๋ถ„๋ฅ˜ ์ „์ฒด๋ณด๊ธฐ (95)
      • ๐Ÿ“Language (42)
        • ๐ŸŒ HTML (3)
        • ๐ŸŸจ Javascript (4)
        • ๐ŸŸฃ PHP (9)
        • ๐ŸŸข Node.js (6)
        • โ˜• Java (10)
        • โž• Python (9)
        • ๐Ÿ”ต C (1)
      • ๐Ÿ“Framework (11)
        • ๐Ÿƒ Spring (1)
        • ๐ŸŽต Laravel (9)
        • ๐Ÿš„ Express (1)
      • ๐Ÿ“DB (7)
        • ๐Ÿฌ MySQL (6)
        • ๐Ÿ˜ PostgreSQL (1)
      • ๐Ÿ“DevOps (6)
      • ๐Ÿ“Book (2)
      • ๐Ÿ“ETC. (16)
        • โš’๏ธ Tool (11)
        • ๐Ÿชข API Connection (5)
      • ๐Ÿ“์ž๊ฒฉ์ฆ ๊ณต๋ถ€ (10)
        • ๐Ÿ“™ SQLD (7)
        • ๐Ÿ“™ ๋ฆฌ๋ˆ…์Šค๋งˆ์Šคํ„ฐ (3)
      • ๐Ÿ“˜ ๋…ธํŠธ (1)
  • ๋ธ”๋กœ๊ทธ ๋ฉ”๋‰ด

    • ๐Ÿ ํ™ˆ
    • ๐Ÿ“ฎ๋ฐฉ๋ช…๋ก
  • ๋งํฌ

    • Github
  • ์ธ๊ธฐ ๊ธ€

  • hELLOยท Designed By์ •์ƒ์šฐ.v4.10.0
yujch
[Github Action] Github Action์„ ์ด์šฉํ•ด์„œ EC2์— ์ž๋™๋ฐฐํฌํ•˜๊ธฐ (์ž‘์„ฑ์ค‘)

๊ฐœ์ธ์ •๋ณด

  • ํ‹ฐ์Šคํ† ๋ฆฌ ํ™ˆ
  • ํฌ๋Ÿผ
  • ๋กœ๊ทธ์ธ
์ƒ๋‹จ์œผ๋กœ

ํ‹ฐ์Šคํ† ๋ฆฌํˆด๋ฐ”

๋‹จ์ถ•ํ‚ค

๋‚ด ๋ธ”๋กœ๊ทธ

๋‚ด ๋ธ”๋กœ๊ทธ - ๊ด€๋ฆฌ์ž ํ™ˆ ์ „ํ™˜
Q
Q
์ƒˆ ๊ธ€ ์“ฐ๊ธฐ
W
W

๋ธ”๋กœ๊ทธ ๊ฒŒ์‹œ๊ธ€

๊ธ€ ์ˆ˜์ • (๊ถŒํ•œ ์žˆ๋Š” ๊ฒฝ์šฐ)
E
E
๋Œ“๊ธ€ ์˜์—ญ์œผ๋กœ ์ด๋™
C
C

๋ชจ๋“  ์˜์—ญ

์ด ํŽ˜์ด์ง€์˜ URL ๋ณต์‚ฌ
S
S
๋งจ ์œ„๋กœ ์ด๋™
T
T
ํ‹ฐ์Šคํ† ๋ฆฌ ํ™ˆ ์ด๋™
H
H
๋‹จ์ถ•ํ‚ค ์•ˆ๋‚ด
Shift + /
โ‡ง + /

* ๋‹จ์ถ•ํ‚ค๋Š” ํ•œ๊ธ€/์˜๋ฌธ ๋Œ€์†Œ๋ฌธ์ž๋กœ ์ด์šฉ ๊ฐ€๋Šฅํ•˜๋ฉฐ, ํ‹ฐ์Šคํ† ๋ฆฌ ๊ธฐ๋ณธ ๋„๋ฉ”์ธ์—์„œ๋งŒ ๋™์ž‘ํ•ฉ๋‹ˆ๋‹ค.