error시에 log를 filter layer에서 프린트하게 변경 (#133) #83
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: dongurami-server-v2 | |
on: | |
push: | |
branches: | |
- develop | |
paths-ignore: | |
- 'README.md' | |
- 'LICENSE' | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Generate Environment Variables File | |
run: | | |
echo "NODE_ENV=${{ secrets.DEV_NODE_ENV }}" >> $GITHUB_ENV | |
echo "PORT=${{ secrets.DEV_PORT }}" >> $GITHUB_ENV | |
echo "RDB_HOST=${{ secrets.DEV_RDB_HOST }}" >> $GITHUB_ENV | |
echo "RDB_PORT=${{ secrets.DEV_RDB_PORT }}" >> $GITHUB_ENV | |
echo "RDB_USER_NAME=${{ secrets.DEV_RDB_USER_NAME }}" >> $GITHUB_ENV | |
echo "RDB_PASSWORD=${{ secrets.DEV_RDB_PASSWORD }}" >> $GITHUB_ENV | |
echo "RDB_DATABASE=${{ secrets.DEV_RDB_DATABASE }}" >> $GITHUB_ENV | |
echo "JWT_SECRET=${{ secrets.DEV_JWT_SECRET }}" >> $GITHUB_ENV | |
echo "DOMAIN=${{ secrets.DEV_DOMAIN }}" >> $GITHUB_ENV | |
cat $GITHUB_ENV | |
- name: Build and package | |
run: | | |
npm install | |
npm run build | |
sudo docker build --platform linux/amd64 \ | |
--build-arg NODE_ENV=${{ secrets.DEV_NODE_ENV }} \ | |
--build-arg PORT=${{ secrets.DEV_PORT }} \ | |
--build-arg RDB_HOST=${{ secrets.DEV_RDB_HOST }} \ | |
--build-arg RDB_PORT=${{ secrets.DEV_RDB_PORT }} \ | |
--build-arg RDB_USER_NAME=${{ secrets.DEV_RDB_USER_NAME }} \ | |
--build-arg RDB_PASSWORD=${{ secrets.DEV_RDB_PASSWORD }} \ | |
--build-arg RDB_DATABASE=${{ secrets.DEV_RDB_DATABASE }} \ | |
--build-arg JWT_SECRET=${{ secrets.DEV_JWT_SECRET }} \ | |
--build-arg DOMAIN=${{ secrets.DEV_DOMAIN }} \ | |
-t ${{ secrets.DOCKER_IMAGE_NAME }}:latest . | |
- name: Login to Docker Hub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Push Docker image | |
run: docker push ${{ secrets.DOCKER_IMAGE_NAME }}:latest | |
build-notify-slack: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Slack Notification | |
id: slack-notification | |
uses: slackapi/slack-github-action@v1.24.0 | |
with: | |
payload: | | |
{ | |
"channel": "${{ secrets.SLACK_BACKEND_CHANNEL_ID }}", | |
"attachments": [ | |
{ | |
"color": "${{ job.status == 'success' && '#36a64f' || job.status == 'failure' && '#ff0000' || '#fffff' }}", | |
"title": "${{ github.repository }}", | |
"title_link": "https://github.com/${{ github.repository }}", | |
"text": "${{ job.status == 'success' && 'GitHub Action Build 성공' || job.status == 'failure' && 'GitHub Action Build 실패 :x:' || '' }}", | |
"fields": [ | |
{ | |
"title": "Repository", | |
"value": "${{ github.repository }}", | |
"short": true | |
}, | |
{ | |
"title": "Tag", | |
"value": "${{ github.ref_name }}", | |
"short": true | |
} | |
] | |
} | |
] | |
} | |
env: | |
SLACK_WEBHOOK_URL: ${{ secrets.DEV_DEPLOY_SLACK_WEBHOOK_URL }} | |
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK | |
deploy: | |
needs: build | |
runs-on: self-hosted # runner로 ec2 연결 | |
steps: | |
- name: Login to Docker Hub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Docker run | |
run: | | |
sudo docker pull ${{ secrets.DOCKER_IMAGE_NAME }}:latest | |
sudo docker-compose down | |
sudo docker-compose up --force-recreate --build -d | |
deploy-notify-slack: | |
needs: deploy | |
runs-on: ubuntu-latest | |
steps: | |
- name: Slack Notification | |
id: slack-notification | |
uses: slackapi/slack-github-action@v1.24.0 | |
with: | |
payload: | | |
{ | |
"channel": "${{ secrets.SLACK_BACKEND_CHANNEL_ID }}", | |
"attachments": [ | |
{ | |
"color": "${{ job.status == 'success' && '#36a64f' || job.status == 'failure' && '#ff0000' || '#fffff' }}", | |
"title": "${{ github.repository }}", | |
"title_link": "https://github.com/${{ github.repository }}", | |
"text": "${{ job.status == 'success' && 'GitHub Action Deploy 성공' || job.status == 'failure' && 'GitHub Action Deploy 실패 :x:' || '' }}", | |
"fields": [ | |
{ | |
"title": "Repository", | |
"value": "${{ github.repository }}", | |
"short": true | |
}, | |
{ | |
"title": "Tag", | |
"value": "${{ github.ref_name }}", | |
"short": true | |
} | |
] | |
} | |
] | |
} | |
env: | |
SLACK_WEBHOOK_URL: ${{ secrets.DEV_DEPLOY_SLACK_WEBHOOK_URL }} | |
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK |