Skip to content

chore: cd 파이프라인 구축 #1

chore: cd 파이프라인 구축

chore: cd 파이프라인 구축 #1

Workflow file for this run

name: Continuous Deployment
on:
push:
branches: ['feature/PW-249-cicd']
permissions:
contents: read
jobs:
deployment:
runs-on: ubuntu-latest
steps:
# 1. Compare branch 코드 내려 받기
- name: Checkout PR
uses: actions/checkout@v4
with:
ref: ${{ github.event.push.base_ref }}
# 2. 노드 버전 명시
- name: Setup Node 18.18.0
uses: actions/setup-node@v4
with:
node-version: 18.18.0
cache: yarn
# 3. yarn 버전 명시
- name: Set yarn version
id: set-version
run: yarn set version 1.22.19
# 4. yarn 캐시 경로 불러오기
- name: Get cache dir path
id: yarn-cache-dir-path
run: echo "CACHE_DIR=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
# 5. yarn 캐싱
- name: Yarn cache
uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.CACHE_DIR }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}-${{ steps.set-version.outputs.YARN_VERSION }}
restore-keys: |
${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}-
# 6. yarn 캐시 체크
- name: Install dependencies
run: |
CACHE_HIT="${{ steps.yarn-cache.outputs.cache-hit }}"
NODE_MODULES_EXISTS=$(test -d "node_modules" && echo "true" || echo "false")
if [[ "$CACHE_HIT" != 'true' || "$NODE_MODULES_EXISTS" == 'false' ]]; then
yarn install
fi
# 7. yarn build
- name: Yarn build
run: yarn build
# 8. Docker 이미지 build 및 push
- name: docker build and push
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -t pennyway/pennyway-webview .
docker push pennyway/pennyway-webview
# 9. AWS SSM을 통한 Run-Command (Docker 이미지 pull 후 docker-compose를 통한 실행)
- name: AWS SSM Send-Command
uses: peterkimzz/aws-ssm-send-command@master
id: ssm
with:
aws-region: ${{ secrets.AWS_REGION }}
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
instance-ids: ${{ secrets.AWS_DEV_INSTANCE_ID }}
working-directory: /home/ubuntu
command: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker system prune -a -f
docker pull pennyway/pennyway-webview
docker run -d -p 3000:3000 pennyway/pennyway-webview