Skip to content

Commit

Permalink
🚀 deploy files setting (#10)
Browse files Browse the repository at this point in the history
Deploy to EC2 instance using GitHub Action and Dockerfile

Related: #9
  • Loading branch information
L-U-Ready authored Oct 13, 2024
1 parent 156f1a9 commit ecf6b11
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Deploy Spring Boot to EC2

on:
push:
branches:
- main
- develop

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up JDK 21
uses: actions/setup-java@v1
with:
java-version: '21'

- name: Build with Gradle
run: ./gradlew build

- name: List build/libs contents
run: ls -la build/libs

- name: Log in to Docker Hub
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin

- name: Build Docker image
run: docker build -t ${{ secrets.DOCKER_USERNAME }}/the_monitor:latest .

- name: Push Docker image
run: docker push ${{ secrets.DOCKER_USERNAME }}/the_monitor:latest

deploy:
runs-on: ubuntu-latest
needs: build

steps:
- name: Connect to EC2 and deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ec2-user
key: ${{ secrets.EC2_PRIVATE_KEY }}
script: |
docker pull ${{ secrets.DOCKER_USERNAME }}/the_monitor:latest
docker stop the_monitor-container || true
docker rm the_monitor-container || true
docker run -d -p 8080:8080 --name the_monitor-container ${{ secrets.DOCKER_USERNAME }}/the_monitor:latest
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM openjdk:21-jdk-slim

WORKDIR /app

COPY build/libs/the_monitor-0.0.1-SNAPSHOT.jar /app/the_monitor.jar

EXPOSE 8080

ENTRYPOINT ["java", "-jar", "/app/the_monitor.jar"]

0 comments on commit ecf6b11

Please sign in to comment.