GitHub Action
github action์ด ๋ญ๋...์ฝ๋๋ฅผ ์ปค๋ฐ/ํธ์ ํ๋ฉด ๊ทธ ํ์ ๋ญ๊ฐ๋ฅผ ํ๊ณ ์ถ๋ค. ci/cd ๋ฑ๋ฑ ๊ผญ ci/cd๊ฐ ์๋๋๋ผ๊ณ ์ปดํ์ผํ ์ปดํ์ผ๋ ํ์ผ์ ๋ฐ์๋ณด๊ณ ์ถ๊ฑฐ๋ s3์ ์ฌ๋ฆฌ๊ณ ์ถ๋ค ๋ฑ์ ๋ฌด์จ์ผ์ด๋ ํ๊ณ ์ถ์ ๊ฑธ ์๋ํ ํด์ฃผ๋ ํด์ด๋ค.
gitlab ci/cd๋ ๊ฐ์ ๊ธฐ๋ฅ์ ํ๋ค. ์ ๋ gitlab ci/cd๊ฐ ๋๋ฌด ์ข์์ ๊ทธ๊ฒ๋ง ์ผ๋๋ฐ ์ด๋ฒ์ github๋ฅผ ์จ์ผํ ์ผ์ด ์๊ฒจ์ ํ์ธํด๋ดค๋๋ gitlab์ ๊ธฐ๋ฅ์ ๋๋ถ๋ถ ๊ฐ์ ธ์ ๊ตฌํํด ๋ฟ๋ค.
์ญ์ ์ด๋ฐ๋ฅ์ ์ข์๊ธฐ๋ฅ์ ๋ค ๋ฒ ๋ผ๋..^^ ์ฐธ๊ณ ๋ก gitlab ci/cd๊ฐ ๋จผ์ ๋์๋ค.
ํด๋ณด์.
workflows
ํ๋ก์ ํธ์ .github/workflows
๋ผ๋ ํด๋๋ฅผ ๋ง๋ค๊ณ ๊ฑฐ๊ธฐ์ build.yml์ ๋ง๋ค์ด ๋ณด์.
cd ~/Desktop/demo-angular
mkdir -p .github/workflows
touch .github/workflows/build.yml
name: CI
on:
push:
branches: [main, dev]
pull_request:
branches: [main, dev]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: ls -alF
run: |
ls -alF
pwd
์ด์ ์ปค๋ฐ ํธ์ํด๋ณด์.
github์น์ฌ์ดํธ์ actionํ์ด์ง์ ๊ฐ๋ณด์.

์๋ณด์ด๋๊ฒ ์๊ธฐ๊ณ ์ฑ๊ณตํ๋ค๊ณ ๋ณด์ฌ์ค๋ค.
ํ์ธํด๋ณด์. create build.yml์ ํด๋ฆญ

ํ๋ฉด์ ๋ณด๋ฉด ls -alF
๋ฅผ ํ๊ณ pwd
๋ฅผ ํด์ ํ์ฌ ํด๋๋ฅผ ํ๋ฆฐํธ ํ๋ค.
์ปค๋ฐ์ ๋ญ๊ฐ๋ฅผ ํด๋ณด๋๊ฑฐ๊น์ง๋ ์ฑ๊ณต
yml์ ์ค๋ช ์ ์ข ํด๋ณด๋ฉด
on:
push:
branches: [main, dev]
pull_request:
branches: [main, dev]
push๋ Pull_request์ main ๋ธ๋์น๋ dev๋ธ๋์น์๋ง ์ด workflow๊ฐ ๋์ํ๋ค.
์ด๋ฏธ์ง๋ ubuntu-latest ๋ฅผ ๊ฐ์ง๊ณ ๋น๋๋ฅผ ์์ํ๋ค.
name
์ ์ฌ๋๋ค์ด ๋ณด๊ธฐ ํธํ๊ฒ ์จ์ฃผ๋ฉด ๋ ๊ฑฐ๊ฐ๊ณ run
์ผ๋ก ์ค์ ์ปค๋งจ๋ค๋ฅผ ์คํํ๋ค.
๋์ถฉ ์ดํดํ์ผ๋ ๋ค์๋จ๊ณ๋ก ๊ฐ๋ณด์.
sample project ์์ฑ
ํ๋ก์ ํธ์ angular ๋ฅผ ํ๋ ์ถ๊ฐํด๋ณด์.
cd Desktop/GitHub
ng new github-action
cd github-action
nb build --prod
์ปค๋ฐ/push
์์ค์ฝ๋๋ฅผ checkout
- name: Checkout
uses: actions/checkout@v2
์ถ๊ฐํ๊ณ ์ปค๋ฐ/ํธ์ ํด๋ณด์.

runner๊ฐ git checkout
์ ํ๊ณ ls -alF๋ฅผ ํด์ ๋ด์ฉ์ด ํ์ธ๋๋ค.

build
nodejs 12 ๋ฒ์ ์ ์ด์ฉ
@angular/cli ๊ฐ ๊ธ๋ก๋ฒ๋ก ์ค์น
npm package install
project build
- name: Checkout
uses: actions/checkout@v2
- name: Node 12.x
uses: actions/setup-node@v2.1.5
with:
node-version: '12.x'
- name: install @angular/cli && npm install && ng build
run: |
npm install -g @angular/cli
npm install
ng build --prod
์ปค๋ฐ/ํธ์ ํ๊ณ ์ก์ ์ ์ฒดํฌํด๋ณด์.
์ค๋ช
์ ํ๋ฉด actions/setup-node@v2.1.5
์ด๊ฒ๋ง ์ค๋ช
ํ๋ฉด๋ ๋ฏ ์ถ๋ค.
github action์ ๋ง์ผ ํ๋ ์ด์ค์ ์ฌ๋๋ค์ด ๋ง๋ค์ด์ ํน์ ์ก์ ์ ๊ณต์ ํด๋๊ณณ์ด ์๋ค. ์์ฃผ ๋ง์ ๋ถ๋ถ๋ค์ด ๋ฒ์จ ๋ง๋ค์ด์ ธ ์์ด์ ๊ทธ๊ฑธ ๊ฐ์ ธ๋ค ์ฌ์ฉํ ์ ์์ด์ ์์ฃผ ํธํ๋ค. ๊ฐ์ธ๋ค์ด ๋ง๋ ๊ฒ๋ ์๊ณ ํน๋ณํ๊ฒ๋ค์ ๊นํ๋ธ์์ ์ง์ ๋ง๋ค์ด๋๊ฒ ์๋ค.
https://github.com/marketplace?type=actions
์ ์ปค๋งจ๋๋ nodejsํ๊ฒฝ์ ๊ตฌ์ถํด์ฃผ๋ ์ก์ ์ธ๋ฐ ๊ฐ์ ธ๋ค ์ฐ๋ฉด ๋๋ค.


๋ง์ง๋ง @ ๋ค์์๋ ๋ฒ์ ์ ์ฐ๋ฉด๋๋๋ฐ ์ต์ ๋ด์ฉ์ ๋ณด๊ณ ์ถ์ผ๋ฉด ๊นํ ํ์ด์ง๋ฅผ ํ์ธํด๋ณด๋ฉด ๋๋ค.

๋ฒ์ ์ ๊ณจ๋ผ์ ์ฌ์ฉํ๋ฉด๋๋ค.
๋น๋๊ฐ ์๋ฃ๋ฌ์ผ๋ ํ์ธํด๋ณด์.

node 12.x๊ฐ ์ ์ค์น๊ฐ ๋์์ผ๋ฉฐ ์ปค๋งจ๋๋ค๋ ์ ์คํ์ด ๋๊ฒ์ ๋ณผ์ ์๋ค.

artifact (๊ฒฐ๊ณผ๋ฌผ)์ ๋ฐ์๋ณด์
๋น๋ํ๊ณ ๋๋ฉด distํด๋์ ๊ฒฐ๊ณผ๋ฌผ์ด ์๊ธด๋ค ์ด๊ฑธ ์ก์ ํ์ด์ง์์ ๋ค์ด๋ฐ์์ ์๊ฒ ํด๋ณด์.
- name: install @angular/cli && npm install && ng build && cd dist
run: |
sudo npm install -g @angular/cli
npm install
ng build --prod
pwd
ls
- uses: actions/upload-artifact@v2
with:
name: github-action
path: dist/github-action/
ํ์ฌ ์์น๋ฅผ ์๊ธฐ ์ํด pwd ์ ls๋ฅผ ์คํํด๋ดค๋ค.
ํด๋ณด์.

ํ์ฌ ํด๋๋ฅผ /home/runner/work/github-action/github-action
์ด๊ณ dist๊ฐ ๋น๋๋์ ์์ฑ๋๊ฒ์ ํ์ธํ ์ ์๋ค.

Artifact๊ฐ ์ ๋ก๋ ๋๊ฒ์ ์์ ์๋ค.
ํด๋ฆญํด์ ๋ค์ด๋ก๋ ๋ฐ์์ ๋ด์ฉ์ ํ์ธํด๋ณด์.

์ ํํ ๋น๋๋๊ฒ์ ์์ ์๋ค.
๋์ถฉ ์ด์ ๋๋ก ์ฐ๋ฉด ๋ฉ๋๋ค. ์ถ๊ฐ๋ก ๋ญ๋ฅผ ํด๋ณผ๊ฐ?
๋น๋ํ s3์ ์ ๋ก๋๋ฅผ ํด๋ณผ๊ฐ์?
main๋ธ๋์น ๋ง๊ณ dev๋ธ๋์น
์ผ๋จ ํ๋ก์ ํธ์ dev ๋ธ๋์น๋ฅผ ๋ง๋ ๋ค.

on:
push:
branches: [main, dev]
pull_request:
branches: [main, dev]
dev์์ ํธ๋ฆฌ๊ฑฐ๊ฐ ๋ ์์๊ฒ ์ถ๊ฐํด์ค๋ค.
์ฐธ๊ณ ๋ก ํน์ ์ก์
์ด ํน์ ๋ธ๋์น์๋ง ์คํ์ด ๋์ผํ๋ฉด if๋ฅผ ์ฌ์ฉํ ์ ์๋ค. if: github.ref == 'refs/heads/dev'
- name: replace staging image version number to sha
if: github.ref == 'refs/heads/dev'
run: |
cd apps/w2ps-staging
[ci skip]
commit ์ [ci skip]์ ๋ณด๋ด๋ฉด ci๋ฅผ ์คํตํ ์ ์๋ค.
s3 ์
๋ก๋
์ผ๋จ ๋ง์ผ ํ๋ ์ด์ค์์ s3๊ด๋ จ ํ๋ฌ๊ทธ์ธ์ ์ฐพ๋๋ค.
https://github.com/marketplace/actions/s3-sync
์ด๊ฒ ์ข์๊ฑฐ๊ฐ๋ค.

ํด๋ณด์.
s3์ ๋ฒํท์ ํ๋ ๋ง๋ค์ด๋๊ณ ์ ์ ๋ฅผ ์์ฑํด์ s3 full๊ถํ์ ์ค๋ค.
- uses: jakejarvis/s3-sync-action@v0.5.1
with:
args: --acl public-read --follow-symlinks --delete
env:
AWS_S3_BUCKET: BUCKET_NAME
AWS_ACCESS_KEY_ID: YOUR_KEY
AWS_SECRET_ACCESS_KEY: YOUR_ACCESS
AWS_REGION: 'us-west-1' # optional: defaults to us-east-1
SOURCE_DIR: 'dist/github-action/' # optional: defaults to entire repository
์ด์ ๋ ํ๋ฉด s3๋ก ์ ๋ก๋๊ฐ ๋๋ค.
argocd์ฒ๋ผ ๋ค๋ฅธ github ํ๋ก์ ํธ์ ์ปค๋ฐํ๊ธฐ
๋น๋ํ๊ณ artifact๋ฅผ ์ ๋ก๋ ํ๊ณ argocd์ ํ๋ก์ ํธ์ ์ปค๋ฐ์ ํด์ผํ๋๊ฒฝ์ฐ ์ํ๋ก์ ํธ๋ฅผ ๋ค์ ์ฒดํฌ์์ ๋ฐ๊ณ ํ์ํ ์์ ์ ํ๊ณ ๋ํ ๋ค์ ์ปค๋ฐํ๋ฉด๋๋ค.
์ฌ๊ธฐ์์ PAT๋ผ๋๊ฒ ์๋๋ฐ ์ด๊ฑด github person access token์ด๋ผ๋๊ฒ์ด๋ค. user >> setting์ ๊ฐ๋ฉด
developer setting์ด ์๋๋ฐ ๊ทธ๊ฑธ ๋๋ฅด๋ฉด access token์ ๋ง๋ค์ ์๋ค. ๋ง๋ค๋ ๊ถํ์ ์ค์ผํ๋๋ฐ repo์ ๋๋ฉด ์ถฉ๋ถํด๋ณด์ธ๋ค. ์์ฑํ $ ๋ค ๋ฃ์ด์ฃผ๊ฑฐ๋ setting์ ๋ฃ์ด์ค๋ ๋๋ค.
- name: Checkout argocd
uses: actions/checkout@v2
with:
repository: wnwusa/argocd
token: ${{ secrets.PAT }}
- name: replace staging image version number to sha
if: github.ref == 'refs/heads/dev'
run: |
cd apps/staging
sed "s/:latest/:${{ github.sha }}/g" 21.deployment-php.origin > 21.deployment-php.yml
- name: replace production image version number to sha
if: github.ref == 'refs/heads/master'
run: |
cd apps/prod
sed "s/:latest/:${{ github.sha }}/g" 21.deployment-php.origin > 21.deployment-php.yml
- name: Commit files
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git commit -am "change docker tag"
git push
์ ์ฒด ์ต๊ทค๋ฌ ๋น๋ ํ์ผ
name: Build
on:
push:
branches: [main, dev]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Node 12.x
uses: actions/setup-node@v2.1.5
with:
node-version: '12.x'
- name: install @angular/cli && npm install
if: github.ref == 'refs/heads/dev'
run: |
npm install -g @angular/cli
npm install
- name: npm run build:staging
if: github.ref == 'refs/heads/dev'
run: |
npm run build:staging
cd dist
pwd
ls
- name: npm run build:production
if: github.ref == 'refs/heads/main'
run: |
npm run build:production
- uses: actions/upload-artifact@v2
with:
name: github-action
path: dist/
- uses: jakejarvis/s3-sync-action@v0.5.1
with:
args: --acl public-read --follow-symlinks --delete
env:
AWS_S3_BUCKET: pickeatup-admin
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID}}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY}}
AWS_REGION: 'us-west-1'
SOURCE_DIR: 'dist/' # optional: defaults to entire repository
Last updated
Was this helpful?