Skip to content

Feat/certification

Feat/certification #31

Workflow file for this run

name: Build and Push Docker Images
# dev 브랜치에 push 될때 작동
on:
push:
branches:
- master
pull_request:
branches:
- master
env:
CURRENT_VERSION: "0.1.0"
jobs:
build-image-and-push:
runs-on: ubuntu-latest
# 권한을 read로 제한
permissions:
contents: read
# jdk 17 설정
steps:
- uses: actions/checkout@v4
# Github Secret to .env
# - name: Create .env file
# run: |
# echo DOCKERHUB_USERNAME=${{ secrets.DOCKER_USERNAME }} >> .env
# echo MYSQL_USERNAME=${{ secrets.MYSQL_USERNAME }} >> .env
# echo MYSQL_PASSWORD=${{ secrets.MYSQL_PASSWORD }} >> .env
# echo MYSQL_HOST=${{ secrets.MYSQL_HOST }} >> .env
# echo MYSQL_DATABASE=${{ secrets.MYSQL_DATABASE }} >> .env
# echo MYSQL_PORT=${{ secrets.MYSQL_PORT }} >> .env
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: "17"
distribution: "temurin"
# gradle 설정
- name: Setup Gradle
uses: gradle/actions/[email protected]
# ./gradlew 권한 부여
- name: Make gradlew executable
run: chmod +x ./gradlew
# 테스트 없이 빌드
- name: Build with Gradle
run: ./gradlew build -x test
- name: Docker Login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Docker Setup Buildx
uses: docker/setup-buildx-action@v2
- name: Build and push Docker images
uses: docker/build-push-action@v4
with:
context: .
file: Dockerfile
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/kukerton:latest
- name: 배포
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_SERVER_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
docker stop $(docker ps -a -q)
docker rm -f $(docker ps -qa)
docker pull ${{ secrets.DOCKER_USERNAME }}/kukerton:latest
docker run -d -p 8080:8080 ${{ secrets.DOCKER_USERNAME }}/kukerton:latest
docker image prune -f