Skip to content

Feat: Dockerfile & GitHub Actions 연동 #15

Feat: Dockerfile & GitHub Actions 연동

Feat: Dockerfile & GitHub Actions 연동 #15

Workflow file for this run

name: Build And Deploy for main branch
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
permissions:
contents: read
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: "adopt"
- name: Make application.properties
run: |
cd ./server/src/main/resources
touch ./application.properties
echo "${{ secrets.PROPERTIES }}" > ./application.properties
shell: bash
- name: Build with Gradle
run: |
cd server
chmod +x ./gradlew
./gradlew clean build -x test
- name: Docker build & push to docker repo
run: |
cd server
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -f Dockerfile -t ${{ secrets.DOCKER_REPO }}:latest .
docker push ${{ secrets.DOCKER_REPO }}:latest
pull-and-deploy:
needs: build-and-push
runs-on: ubuntu-latest
steps:
- name: Pull & Deploy to server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_PUBLIC_IP }}
username: ubuntu
key: ${{ secrets.SSH_PRIVATE_KEY }}
envs: GITHUB_SHA
script: |
sudo docker rm -f $(docker ps -qa)
sudo docker pull ${{ secrets.DOCKER_REPO }}:latest
sudo docker image prune -f
sudo docker run -d --name server -p 80:8080 suhwani/capstone