Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,24 @@ on:
jobs:
build-and-deploy:
runs-on: ubuntu-latest
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock

steps:
- name: Checkout source
uses: actions/checkout@v4

- name: Make Gradle wrapper executable
run: chmod +x ./gradlew

- name: Build JAR
run: ./gradlew clean build -x test --no-daemon

- name: Rename JAR to app.jar
run: |
cp build/libs/*-SNAPSHOT.jar build/libs/app.jar

- name: Setup SSH with ssh-agent
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
run: |
mkdir -p ~/.ssh
ssh-agent -a $SSH_AUTH_SOCK > /dev/null
Expand All @@ -31,22 +38,21 @@ jobs:
ssh-keyscan -H "${{ secrets.SERVER_HOST }}" >> ~/.ssh/known_hosts

- name: Verify SSH connection
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
run: |
ssh ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }} "echo 'SSH connection successful'"
ssh -o StrictHostKeyChecking=no \
${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }} \
"echo 'SSH connection successful'"

- name: Upload JAR to server
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
- name: Upload all deploy files
run: |
rsync -avz -e "ssh" \
build/libs/*.jar \
${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }}:${{ secrets.DEPLOY_PATH }}/app.jar
build/libs/app.jar \
Dockerfile \
docker-compose.yml \
${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }}:${{ secrets.DEPLOY_PATH }}/

- name: Deploy via Docker Compose
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
run: |
ssh ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }} << 'ENDSSH'
Expand Down
9 changes: 1 addition & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
FROM gradle:8.3-jdk17 AS builder
WORKDIR /app
COPY . .
RUN gradle clean build -x test --no-daemon

FROM eclipse-temurin:17-jre-jammy
WORKDIR /app
COPY --from=builder /app/build/libs/*.jar app.jar

COPY app.jar app.jar
EXPOSE 8080

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