Skip to content

Build: del jcenter

Build: del jcenter #56

Workflow file for this run

name: Java CI with Gradle
# 동작 조건 설정 : main 브랜치에 push가 발생할 경우 동작한다.
on:
push:
branches: [ "develop" ]
permissions:
contents: read
id-token: write
jobs:
# Spring Boot 애플리케이션을 빌드하여 도커허브에 푸시하는 과정
build-docker-image:
runs-on: ubuntu-22.04
steps:
- name: checkout
uses: actions/checkout@v4
# 환경 변수 설정 (Firebase)
- name: create-json
id: create-json
uses: jsdaniell/[email protected]
with:
name: "drugbox_firebase.json"
json: ${{ secrets.GCP_CREDENTIAL_JSON }}
dir: 'src/main/resources'
- name: Set GOOGLE_APPLICATION_CREDENTIALS environment variable
run: echo "GOOGLE_APPLICATION_CREDENTIALS=src/main/resources/drugbox_firebase.json" >> $GITHUB_ENV
# Google credentials
- name: google-credentials
uses: 'google-github-actions/auth@v2'
with:
credentials_json: '${{ secrets.GCP_CREDENTIAL_JSON }}'
project_id: '${{ secrets.GCP_PROJECT_ID }}'
#workload_identity_provider: '${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }}'
#service_account: '${{ secrets.GCP_SERVICE_ACCOUNT }}'
- name: 'Set up Cloud SDK'
uses: 'google-github-actions/setup-gcloud@v2'
- name: 'Use gcloud CLI'
run: 'gcloud info'
# 1. Java 세팅
- name: Set up JDK 11
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'temurin'
# - name: make application.yml
# run: |
# mkdir ./src/main/resources
# cd ./src/main/resources
# touch ./application.yml
#
# # GitHub-Actions 에서 설정한 값을 application.yml 파일에 쓰기
# echo "${{ secrets.PROPERTIES_YML }}" >> ./application.yml
# shell: bash
- name: make application.properties
run: |
cd ./src/main/resources
touch ./application.properties
# GitHub-Actions 에서 설정한 값을 application.properties 파일에 쓰기
echo "${{ secrets.APPLICATION_PROPERTIES }}" >> ./application.properties
shell: bash
# 2. Spring Boot 애플리케이션 빌드
- name: Build with Gradle
run: |
chmod +x ./gradlew
./gradlew clean build --refresh-dependencies
./gradlew clean bootJar -x test
# 3. Docker 이미지 빌드
- name: docker image build
run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/drugbox-grad .
# 4. DockerHub 로그인
- name: docker login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
# 5. Docker Hub 이미지 푸시
- name: docker Hub push
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/drugbox-grad
# 6. EC2 보안그룹에 Github Actions 추가
- name: Get Github action IP
id: ip
uses: haythem/[email protected]
- 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: ap-northeast-2
- name: Add Github Actions IP to Security group
run: |
aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32
# Deploy Images with Docker compose
- name: executing remote ssh commands using password
uses: appleboy/ssh-action@master
env:
APP: "drugbox-grad"
COMPOSE: "/home/ubuntu/compose/docker-compose.yml"
with:
username: ubuntu
host: ${{ secrets.EC2_HOST }}
key: ${{ secrets.EC2_PRIVATE_KEY }}
port: ${{ secrets.EC2_SSH_PORT }}
envs: APP, COMPOSE
script_stop: true
script: |
sudo docker-compose -f $COMPOSE down
sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/drugbox-grad
sudo docker-compose -f $COMPOSE up -d
- name: Remove Github Actions IP from security group
run: |
aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32