Skip to content

Commit

Permalink
Chore: AWS EC2 Deploy Test (#428)
Browse files Browse the repository at this point in the history
* Chore: dev CD pipeline 수정 (#421)

* Fix: 과릿 1.3.5 (#410)

* Fix: 과릿 1.3.5 (#411)

* Fix: 과릿 1.3.5

* Fix: 과릿 1.3.5

* Fix: 과릿 1.3.5 (#412)

* Fix: 과릿 1.3.5

* Fix: 과릿 1.3.5

* Fix: 과릿 1.3.5

* Fix: 과릿 1.3.5 (#410)

* Fix: 과릿 1.3.5 (#412)

* Fix: 과릿 1.3.5

* Fix: 과릿 1.3.5

* Fix: 과릿 1.3.5

* Chore: dev CD pipeline 수정 (#421)

* Chore: dev CD pipeline 수정 (#421)

* Chore: dev CD pipeline 수정 (#421)

* Chore: dev CD pipeline 수정 (#421)

* Chore: dev CD pipeline 수정 (#421)

* Style: 주석 삭제 (#421)

* Chore: DEV, RELEASE Pipeline 수정 (#421)
  • Loading branch information
dl-00-e8 authored Apr 6, 2024
1 parent 1b274b5 commit f7aeade
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 25 deletions.
28 changes: 20 additions & 8 deletions .github/workflows/dev-CD.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: DEV Dockerhub Push
name: Push Image to Amazon ECR

on:
push:
Expand All @@ -7,6 +7,7 @@ on:
env:
AWS_REGION: ap-northeast-2
ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }}
GITHUB_SHA: ${{ github.sha }}

jobs:
build:
Expand Down Expand Up @@ -70,20 +71,31 @@ jobs:
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

# Docker Image Push to ECR
# Docker Image Push to ECR and Run container with Image pull from ECR
- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
IMAGE_TAG: ${{ env.GITHUB_SHA }}
run: |
# Build a docker container and push it to ECR so that it can be deployed to ECS.
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
- name: Pull image from Amazon ECR and restart container
run: |
docker pull $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG ${{ secrets.DOCKER_IMAGE_NAME }}
docker-compose up -d
# Docker Compose
# docker-compose stop ${{ secrets.DOCKER_SERVICE_NAME }}
# docker-compose rm -f ${{ secrets.DOCKER_SERVICE_NAME }}
- name: Docker Compose
uses: appleboy/ssh-action@master
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ env.GITHUB_SHA }}
with:
host: ${{ secrets.AWS_SERVER_IP }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY}}
docker tag ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY}} ${{ secrets.DOCKER_IMAGE_NAME }}
docker-compose up -d
58 changes: 41 additions & 17 deletions .github/workflows/release-CD.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
name: Beanstalk Deploy
name: Deploy release version

on:
push:
branches:
- release

env:
AWS_REGION: ap-northeast-2
ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }}
GITHUB_SHA: ${{ github.sha }}

jobs:
build:
# ubuntu 버전 지정
Expand Down Expand Up @@ -40,43 +45,62 @@ jobs:
run: |
cd ./src/main/resources
touch ./application-secret.yml
echo "${{ secrets.APPLICATION_SECRET}}" > ./application-secret.yml
echo "${{ secrets.APPLICATION_SECRET }}" > ./application-secret.yml
shell: bash

# release.yml 반영
- name: Make application-release.yml
run: |
cd ./src/main/resources
echo "${{ secrets.GCP_APPLICATION_RELEASE}}" > ./application-release.yml
echo "${{ secrets.APPLICATION_RELEASE }}" > ./application-release.yml
shell: bash

# Gradle BootJar
- name: BootJar with Gradle
run: ./gradlew clean bootJar -Dspring.profiles.active=release

# Docker Image Push
- name: Docker Image push
# Configure AWS Credentials by using IAM inform
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }} # 나의 ECR 정보
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}

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

# Docker Image Push to ECR and Run container with Image pull from ECR
- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ env.GITHUB_SHA }}
run: |
docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }}
docker build -t ${{ secrets.DOCKERHUB_USERNAME}}/${{ secrets.DOCKERHUB_REPOSITORY}} ./
docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY}}
# Build a docker container and push it to ECR so that it can be deployed to ECS.
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
# Docker Compose
}
- name: Docker Compose
uses: appleboy/ssh-action@master
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ env.GITHUB_SHA }}
with:
host: ${{ secrets.GCP_SERVER_IP }}
host: ${{ secrets.AWS_SERVER_IP }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
passphrase: ${{ secrets.SSH_PASSPHRASE }}
envs: GITHUB_SHA
script: |
sudo docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }}
sudo docker-compose stop ${{ secrets.DOCKER_SERVICE_NAME }}
sudo docker-compose rm -f ${{ secrets.DOCKER_SERVICE_NAME }}
sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY}}
sudo docker tag ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY}} ${{ secrets.DOCKER_IMAGE_NAME }}
sudo docker-compose up -d
docker-compose stop ${{ secrets.DOCKER_SERVICE_NAME }}
docker-compose rm -f ${{ secrets.DOCKER_SERVICE_NAME }}
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY}}
docker tag ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY}} ${{ secrets.DOCKER_IMAGE_NAME }}
docker-compose up -d
#name: Beanstalk Deploy
Expand Down

0 comments on commit f7aeade

Please sign in to comment.