처음 설계를 할 때 프리티어 ec2
에 컨테이너를 띄우고 깃 액션
에서 이미지를 만들어 latest
이미지를 재실행으로 배포 하려함
프리티어 메모리 부족문제로 빌드 부터 막힘 ㅜㅜ
dist
폴더를 ec2로 전송하고name: CD
on:
push:
tags:
- "v*"
jobs:
wait-for-ci:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
steps:
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
registry-url: "https://npm.pkg.github.com"
- name: Wait for CI check to pass
uses: fountainhead/action-wait-for-check@v1.0.0
id: wait-for-ci
with:
token: ${{ secrets.GITHUB_TOKEN }}
checkName: build (16.x)
ref: ${{ github.event.head }}
- name: Stop workflow
if: steps.wait-for-ci.outputs.conclusion != 'success'
run: node -e 'process.exit(1)'
image-push-scp-build-file:
needs: wait-for-ci
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
registry-url: "https://npm.pkg.github.com"
- name: Install dependencies
run: npm install
- name: Run Build
run: npm run build
- name: Set env
run: |
... // 정보 보호
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.CR_PAT }}
- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
target: prod
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/${{env.REPOSITORY_NAME}}:latest
ghcr.io/${{ github.repository_owner }}/${{env.REPOSITORY_NAME}}:${{ env.RELEASE_VERSION }}
- name: build file upload to ec2
uses: garygrossgarten/github-action-scp@release
with:
local: ./dist
remote: /home/ubuntu/volunteer-server/dist/
host: ${{ secrets.HOST }}
username: ${{ secrets.SSH_USER }}
privateKey: ${{ secrets.SSH_KEY }}
recursive: true
- name: ec2 update
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
script: |
export NVM_DIR=~/.nvm
source ~/.nvm/nvm.sh
pm2 restart 0 --update-env
appleboy/ssh-action@master
스크립트 권한
https://padawanr0k.github.io/posts/github/githubAction/
https://github.com/appleboy/scp-action
https://stackoverflow.com/questions/62863080/github-actions-err-bash-line-3-npm-command-not-found