Skip to content

self-hosted runners & docker compose test #113

self-hosted runners & docker compose test

self-hosted runners & docker compose test #113

Workflow file for this run

name: Build and Deploy to EC2
on:
push:
branches: [ "production", "main", "feat/173-docker-deploy" ]
pull_request:
branches: [ "production", "main" ]
env:
AWS_REGION: ap-northeast-2
AWS_S3_BUCKET: gitget-bucket-hey
AWS_CODE_DEPLOY_APPLICATION: GitGet-Application-HEY
AWS_CODE_DEPLOY_GROUP: GitGet-CICD-group-hey
DOCKER_HUB_REPOSITORY: geniusgitget/gitget
jobs:
backend-docker-build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
# Actions
- name: Checkout
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
# 프로젝트 내 yml 파일 실행
- name: make application.yml
run: |
mkdir -p ./src/main/resources
cd ./src/main/resources
touch ./application.yml
touch ./application-common.yml
touch ./application-prod.yml
echo "${{ secrets.APPLICATION }}" > ./application.yml
echo "${{ secrets.COMMON }}" > ./application-common.yml
echo "${{ secrets.PROD }}" > ./application-prod.yml
- name: make test application.yml
run: |
mkdir -p ./src/test/resources
cd ./src/test/resources
touch ./application.yml
touch ./application-test.yml
echo "${{ secrets.APPLICATION_TEST }}" > ./application.yml
echo "${{ secrets.TEST }}" > ./application-test.yml
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
shell: bash
- name: Build with Gradle
run: ./gradlew clean build
# - name: Make zip file
# run: zip -r ./$GITHUB_SHA.zip .
# shell: bash
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Docker Image Build and Push
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
platforms: linux/amd64
push: true
tags: ${{ env.DOCKER_HUB_REPOSITORY }}:latest
backend-docker-pull-and-run:
runs-on: [ self-hosted, dev ]
if: ${{ needs.backend-docker-build-and-push.result == 'success' }}
needs: [ backend-docker-build-and-push ]
steps:
- name: Execute Deploy Script
run: |
sh /home/ubuntu/deploy.sh
# - name: Access to AWS
# uses: aws-actions/configure-aws-credentials@v1
# with:
# aws-region: ${{ env.AWS_REGION }}
# aws-access-key-id: ${{ secrets.CICD_ACCESS_KEY_HEY }}
# aws-secret-access-key: ${{ secrets.CICD_SECRET_KEY_HEY }}
# - name: Upload to S3
# run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://$AWS_S3_BUCKET/$GITHUB_SHA.zip
# - name: Code Deploy
# run: aws deploy create-deployment --application-name GitGet-Application-HEY --deployment-config-name CodeDeployDefault.AllAtOnce --deployment-group-name GitGet-CICD-group-hey --s3-location bucket=$AWS_S3_BUCKET,key=$GITHUB_SHA.zip,bundleType=zip