Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/staging' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
coding-convention committed Nov 9, 2023
2 parents 15e995b + 7f9e4d1 commit 2548177
Showing 1 changed file with 107 additions and 0 deletions.
107 changes: 107 additions & 0 deletions .github/workflows/Prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: Build and Push to ECR
on:
push:
branches:
- main # Change this to your desired branch
env:
REGION: ap-northeast-2 # Seoul


jobs:
build-and-push:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
check-latest: true

- name: make application.yml
run: |
mkdir ./src/main/resources
cd ./src/main/resources
touch ./application.yml
echo "${{ secrets.YML }}" > ./application.yml
shell: bash

- name: make application-dev.yml
run: |
cd ./src/main/resources
touch ./application-dev.yml
echo "${{ secrets.YML_PROD }}" > ./application-dev.yml
cat ./application-dev.yml
shell: bash

- name: Setup Gradle 7.6
uses: gradle/gradle-build-action@v2
with:
gradle-version: 7.6

- name: Gradle Caching
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Build Spring Boot application
run: gradle build

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.REGION }}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Build and tag Docker image
run: |
docker build -t ${{ secrets.ECR_REGISTRY }}/prod:latest .
- name: Push Docker image to ECR
run: |
docker push ${{ secrets.ECR_REGISTRY }}/prod:latest
deploy:
needs: build-and-push
runs-on: ubuntu-latest

steps:
- name: Deploy on Staging Server
uses: appleboy/ssh-action@v0.1.10
with:
host: ${{ secrets.AWS_STAGING }}
username: ${{ secrets.AWS_SSH_USERNAME }}
key: ${{ secrets.AWS_SSH_KEY }}
script_stop: true
script: |
cd /app
password=$(aws ecr get-login-password --region ${{ env.REGION }})
docker login --username AWS --password $password ${{ secrets.ECR_REGISTRY }}
docker-compose pull
docker-compose up -d
# notification:
# needs: deploy
# runs-on: ubuntu-latest
#
# steps:
# - name: Send Discord Notification
# run: |
# curl -X POST \
# -H "Content-Type: application/json" \
# -d '{"username": "'"${GITHUB_ACTOR}"'", "content": "효근아 서버 올라갔어~"}' \
# ${{ secrets.DISCORD_WEBHOOK }}

0 comments on commit 2548177

Please sign in to comment.