diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 5a3d708..d1315c3 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -33,8 +33,7 @@ jobs: ${{ runner.os }}-gradle- - name: Grant execute permission for gradlew - run: - chmod +x gradlew + run: chmod +x gradlew ## create application-prod.yml - name: create application.yml @@ -48,22 +47,6 @@ jobs: - name: Build with Gradle run: ./gradlew build -x test - ## docker build & push to production - - name: Build Docker image - run: docker build --tag acchotsix/acc-hotsix:latest . - - - name: Log in to DockerHub - uses: docker/login-action@v3.1.0 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Push image to DockerHub - run: docker push acchotsix/acc-hotsix:latest - - - name: Make zip file - run: zip -r ./hotsix.zip . - ## deploy to production - name: Configure AWS IAM credentials uses: aws-actions/configure-aws-credentials@v1 @@ -72,12 +55,38 @@ jobs: aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }} aws-region: ap-northeast-2 + - name: Login to ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + + ## docker build + - name: build docker file and setting deploy files + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + ECR_REPOSITORY: acc6-ecr + IMAGE_TAG: ${{ github.sha }} + run: | + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG + mkdir scripts + touch scripts/deploy.sh + echo "aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin $ECR_REGISTRY" >> scripts/deploy.sh + echo "docker pull $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> scripts/deploy.sh + echo "docker run -p 8080:8080 -e PROFILE=dev -d --restart always --name csbroker-api $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> scripts/deploy.sh + - name: Upload to S3 - run: aws s3 cp --region ap-northeast-2 ./hotsix.zip s3://acc6-s3-dev-an2/hotsix.zip #버킷에 업로드. + env: + IMAGE_TAG: ${{ github.sha }} + run: | + zip -r deploy-$IMAGE_TAG.zip ./scripts appspec.yml + aws s3 cp --region ap-northeast-2 --acl private ./deploy-$IMAGE_TAG.zip s3://acc6-s3-dev-an2 - name: Start CodeDeploy Agent - run: > + env: + IMAGE_TAG: ${{ github.sha }} + run: | aws deploy create-deployment --application-name hotsix - --deployment-config-name CodeDeployDefault.AllAtOnce --deployment-group-name deploy-group - --s3-location bucket=acc6-s3-dev-an2,bundleType=zip,key=hotsix.zip + --deployment-config-name CodeDeployDefault.AllAtOnce + --s3-location bucket=acc6-s3-dev-an2,bundleType=zip,key=deploy-$IMAGE_TAG.zip + --debug diff --git a/appspec.yml b/appspec.yml index 3098c23..bde024e 100644 --- a/appspec.yml +++ b/appspec.yml @@ -2,17 +2,18 @@ version: 0.0 os: linux files: - source: / - destination: /home/ubuntu + destination: /home/ubuntu/app overwrite: yes permissions: - - object: /home/ubuntu + - object: / pattern: "**" - owner: root - group: root + owner: ubuntu + group: ubuntu + mode: 755 hooks: - ApplicationStart: - - location: scripts/run_docker.sh - timeout: 120 - runas: root \ No newline at end of file + AfterInstall: + - location: scripts/deploy.sh + timeout: 60 + runas: ubuntu \ No newline at end of file diff --git a/scripts/run_docker.sh b/scripts/run_docker.sh deleted file mode 100644 index 5e09f82..0000000 --- a/scripts/run_docker.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -docker pull acchotsix/acc-hotsix -docker run -d -p 80:8080 acchotsix/acc-hotsix:latest \ No newline at end of file