release/0402-01 (#261) #61
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: 'deploy' | |
on: | |
push: | |
paths: | |
- '.github/workflows/**' | |
- 'src/**' | |
- 'build.gradle' | |
- 'Dockerfile' | |
- 'readme.md' | |
- 'infraScript/**' | |
branches: | |
- 'main' | |
jobs: | |
makeTagAndRelease: | |
runs-on: ubuntu-latest | |
outputs: | |
tag_name: ${{ steps.create_tag.outputs.new_tag }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Create Tag | |
id: create_tag | |
uses: mathieudutour/github-tag-action@v6.1 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Create Release | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ steps.create_tag.outputs.new_tag }} | |
release_name: Release ${{ steps.create_tag.outputs.new_tag }} | |
body: ${{ steps.create_tag.outputs.changelog }} | |
draft: false | |
prerelease: false | |
buildImageAndPush: | |
name: 도커 이미지 빌드와 푸시 | |
needs: makeTagAndRelease | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Docker Buildx 설치 | |
uses: docker/setup-buildx-action@v2 | |
- name: 레지스트리 로그인 | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: set lower case owner name | |
run: | | |
echo "OWNER_LC=${OWNER,,}" >> ${GITHUB_ENV} | |
env: | |
OWNER: "${{ github.repository_owner }}" | |
- name: application-secret.yml 생성 | |
env: | |
ACTIONS_STEP_DEBUG: true | |
APPLICATION_SECRET: ${{ secrets.APPLICATION_SECRET_YML }} | |
run: echo "$APPLICATION_SECRET" > src/main/resources/application-secret.yml | |
- name: 빌드 앤 푸시 | |
uses: docker/build-push-action@v3 | |
with: | |
context: . | |
push: true | |
tags: | | |
ghcr.io/${{ env.OWNER_LC }}/everycharge:${{ needs.makeTagAndRelease.outputs.tag_name }}, | |
ghcr.io/${{ env.OWNER_LC }}/everycharge:latest | |
deploy: | |
runs-on: ubuntu-latest | |
needs: [ buildImageAndPush ] | |
steps: | |
- 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: "i-01e641368202eb226" | |
working-directory: / | |
comment: Deploy | |
command: | | |
mkdir -p /docker_projects/everycharge | |
curl -o /docker_projects/everycharge/zero_downtime_deploy.py https://raw.githubusercontent.com/EVeryCharge/EVeryCharge-Api-Server/main/infraScript/zero_downtime_deploy.py | |
chmod +x /docker_projects/everycharge/zero_downtime_deploy.py | |
/docker_projects/everycharge/zero_downtime_deploy.py | |
docker rmi $(docker images -f "dangling=true" -q) | |
docker system prune -a --volumes |