forked from Challengers-BOD/BOD
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
89 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
name: Deploy to EC2 and RDS | ||
|
||
on: | ||
push: | ||
branches: [ dev ] | ||
|
||
env: | ||
DOCKER_IMAGE_TAG_NAME: backend | ||
|
||
jobs: | ||
build-and-docker-push: | ||
runs-on: ubuntu-22.04 | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
# java version 지정 | ||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
|
||
# 권한 부여 | ||
- name: Grant execute permission for gradlew | ||
run: chmod +x gradlew | ||
|
||
# Build | ||
- name: Build with Gradle | ||
run: ./gradlew clean build | ||
|
||
# Docker Image 빌드 | ||
- name: Build the Docker image | ||
run: docker build . --file Dockerfile --tag ${{ secrets.QA_DOCKERHUB_USERNAME }}/${{ env.DOCKER_IMAGE_TAG_NAME }}:latest | ||
|
||
# Docker 로큰 | ||
- name: Login to Docker Hub using Access Token | ||
run: echo "${{ secrets.QA_DOCKERHUB_TOKEN }}" | docker login -u ${{ secrets.QA_DOCKERHUB_USERNAME }} --password-stdin | ||
|
||
# 이미지 푸시 | ||
- name: Push the Docker image | ||
run: docker push ${{ secrets.QA_DOCKERHUB_USERNAME }}/${{ env.DOCKER_IMAGE_TAG_NAME }}:latest | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
# - name: Login to Docker Hub | ||
# uses: docker/login-action@v3 | ||
# with: | ||
# username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
# password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
# | ||
# - name: Set up Docker Builds | ||
# uses: docker/setup-buildx-action@v3 | ||
# | ||
# - name: Build and push | ||
# uses: docker/build-push-action@v6 | ||
# with: | ||
# context: . | ||
# file: Dockerfile | ||
# push: true | ||
# tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.DOCKER_IMAGE_TAG_NAME }}:latest | ||
|
||
|
||
deploy-to-ec2: | ||
needs: build-and-docker-push # 위의 build-and-docker-push 이 끝나고 실행 | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Deploy to EC2 | ||
uses: appleboy/[email protected] | ||
with: | ||
host: ${{ secrets.QA_EC2_HOST }} | ||
username: ${{ secrets.QA_EC2_USER }} | ||
key: ${{ secrets.QA_EC2_KEY }} | ||
script: | | ||
CONTAINER_ID=$(sudo docker ps -q --filter "publish=8080-8080") | ||
if [ ! -z "$CONTAINER_ID" ]; then | ||
sudo docker stop $CONTAINER_ID | ||
sudo docker rm $CONTAINER_ID | ||
fi | ||
# 여기서의 환경 변수도 여러분 상황에 맞게 작성하시면 됩니다!!! | ||
sudo docker pull ${{ secrets.QA_DOCKERHUB_USERNAME }}/${{ env.DOCKER_IMAGE_TAG_NAME }}:latest | ||
sudo docker run -d -p 8080:8080 \ | ||
-e DB_USERNAME=${{secrets.DB_USERNAME}} \ | ||
-e DB_PASSWORD=${{secrets.DB_PASSWORD}} \ | ||
-e DB_URL=${{ secrets.DB_URL }} \ | ||
${{ secrets.QA_DOCKERHUB_USERNAME }}/${{ env.DOCKER_IMAGE_TAG_NAME }}:latest |