fix: versioning 테스트 #76
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: Develop Build & Deploy | |
on: | |
push: | |
branches: [ "fix/#88-docker-deploy-platform" ] | |
env: | |
DOCKERHUB_IMAGE_NAME: walwal-server | |
jobs: | |
build-deploy: | |
runs-on: ubuntu-latest | |
environment: DEV | |
strategy: | |
matrix: | |
java-version: [ 17 ] | |
distribution: [ 'zulu' ] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
# JDK를 17 버전으로 세팅 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: ${{ matrix.java-version }} | |
distribution: ${{ matrix.distribution }} | |
- name: Grant execute permission for gradlew | |
run: chmod +x ./gradlew | |
- name: Build with Gradle | |
id: gradle | |
uses: gradle/gradle-build-action@v3 | |
with: | |
arguments: | | |
build | |
--scan | |
cache-read-only: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/develop' }} | |
# Docker 이미지 빌드 및 도커 허브 푸시 | |
- name: Docker build & push | |
run: | | |
docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_TOKEN }} | |
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.DOCKERHUB_IMAGE_NAME }} . | |
docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.DOCKERHUB_IMAGE_NAME }} | |
# 서버로 docker-compose 파일 전송 | |
- name: Copy docker-compose file to EC2 | |
uses: burnett01/[email protected] | |
with: | |
switches: -avzr --delete | |
remote_host: ${{ secrets.EC2_HOST }} | |
remote_user: ${{ secrets.EC2_USERNAME }} | |
remote_key: ${{ secrets.EC2_PRIVATE_KEY }} | |
path: docker-compose.yaml | |
# root path | |
remote_path: /home/ec2-user/ | |
- name: Copy default.conf to EC2 | |
uses: burnett01/[email protected] | |
with: | |
switches: -avzr --delete | |
remote_host: ${{ secrets.EC2_HOST }} | |
remote_user: ${{ secrets.EC2_USERNAME }} | |
remote_key: ${{ secrets.EC2_PRIVATE_KEY }} | |
path: ./nginx | |
remote_path: /home/ec2-user/ | |
- name: Current Time | |
uses: gerred/[email protected] | |
id: current-time | |
- name: Replace string | |
uses: frabert/[email protected] | |
id: format-time | |
with: | |
pattern: '[:\.]+' | |
string: "${{ steps.current-time.outputs.time }}" | |
replace-with: '-' | |
flags: 'g' | |
- name: Prepare deployment package | |
run: | | |
zip -r deployment-package.zip docker-compose.yaml nginx/default.conf | |
- name: Beanstalk Deploy | |
uses: einaregilsson/beanstalk-deploy@v22 | |
with: | |
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
existing_bucket_name: "walwal-server-dev-deployment" | |
application_name: "walwal-dev" | |
environment_name: "Walwal-dev-env" | |
version_label: "walwal-dev-${{ github.run_id }}-${{ steps.format-time.outputs.replaced }}" | |
region: ap-northeast-2 | |
deployment_package: deployment-package.zip | |
wait_for_environment_recovery: 180 | |
# Slack 알림 | |
- name: Send Deploy Result to Slack | |
uses: rtCamp/action-slack-notify@v2 | |
env: | |
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }} | |
SLACK_USERNAME: 왈왈봇 | |
SLACK_COLOR: ${{ job.status == 'success' && 'good' || 'danger' }} | |
SLACK_TITLE: "Deploy Summary - Develop" | |
SLACK_MESSAGE: | | |
- image tag: `${{ steps.metadata.outputs.tags }}` | |
- build scan report: ${{ steps.gradle.outputs.build-scan-url }} | |
- deploy status: ${{ job.status }} | |
- deploy time: ${{ steps.current-time.outputs.time }} |