Skip to content

release: 1.10.0

release: 1.10.0 #50

Workflow file for this run

name: Build and Push Docker Images
on:
pull_request:
branches:
- main
jobs:
build-and-push-backend:
if: ${{ startsWith(github.event.pull_request.head.ref, 'release/') || startsWith(github.event.pull_request.head.ref, 'hotfix/') }}
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.PERSONAL_GITHUB_TOKEN }}
- name: Set VERSION from PR title
run: |
VERSION=$(echo "${{ github.event.pull_request.title }}" | sed -n 's/^\(release\|hotfix\): \(.*\)/\2/p')
echo "VERSION=${VERSION}" >> $GITHUB_ENV
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'corretto'
- name: gradle 실행 권한 부여
run: chmod +x ./gradlew
- name: gradle 빌드
run: ./gradlew build -x test --no-daemon
- name: Build and push backend Docker image
run: |
echo "${{ env.VERSION }}"
echo "${{ secrets.PERSONAL_GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
docker build -t ghcr.io/${{ github.repository }}:${{ env.VERSION }} .
docker push ghcr.io/${{ github.repository }}:${{ env.VERSION }}
echo "IMAGE_NAME=ghcr.io/${{ github.repository }}:${{ env.VERSION }}" >> $GITHUB_ENV
- name: SSH into EC2 and deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.EC2_KEY }}
script: |
echo "${{ secrets.PERSONAL_GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
docker pull ${{ env.IMAGE_NAME }}
docker rm -f backend
docker run -d --log-driver=syslog --name backend -p 8080:8080 \
--network my-network \
-e SPRING_PROFILES_ACTIVE=prod \
${{ env.IMAGE_NAME }}
docker image prune -a -f