feat: changed deploy.yml

This commit is contained in:
filippo-ferrari 2024-09-06 19:48:36 +02:00
parent af2b22e79c
commit 8dc1e23651
3 changed files with 87 additions and 28 deletions

View file

@ -13,26 +13,30 @@ jobs:
- name: Checkout the code - name: Checkout the code
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build Docker image
run: |
docker build -t vaadin-app .
- name: Set up SSH - name: Set up SSH
uses: webfactory/ssh-agent@v0.5.3 uses: webfactory/ssh-agent@v0.5.3
with: with:
ssh-private-key: ${{ secrets.SSH_KEY }} ssh-private-key: ${{ secrets.SSH_KEY }}
- name: Copy files to server - name: Deploy Docker image
run: |
scp -o StrictHostKeyChecking=no docker-compose.yml Dockerfile ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:/home/${{ secrets.SSH_USER }}/munera/
scp -o StrictHostKeyChecking=no target/your-application.jar ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:/home/${{ secrets.SSH_USER }}/munera/
- name: Deploy on server
run: | run: |
ssh -o StrictHostKeyChecking=no ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} << 'EOF' ssh -o StrictHostKeyChecking=no ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} << 'EOF'
cd /home/${{ secrets.SSH_USER }}/munera docker pull vaadin-app || true
echo "DB_ADDRESS=${DB_ADDRESS}" > .env docker stop vaadin-app || true
echo "DB_USER=${DB_USER}" >> .env docker rm vaadin-app || true
echo "DB_PASSWORD=${DB_PASSWORD}" >> .env docker run -d --name vaadin-app -p 8080:8080 \
echo "DB_NAME=${DB_NAME}" >> .env -e DB_ADDRESS=${DB_ADDRESS} \
docker-compose down -e DB_USER=${DB_USER} \
docker-compose up -d --build -e DB_PASSWORD=${DB_PASSWORD} \
-e DB_NAME=${DB_NAME} \
vaadin-app
EOF EOF
env: env:
DB_ADDRESS: ${{ secrets.DB_ADDRESS }} DB_ADDRESS: ${{ secrets.DB_ADDRESS }}

41
.github/workflows/deploy.yml.bak vendored Normal file
View file

@ -0,0 +1,41 @@
name: Deploy to Debian Server
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v2
- name: Set up SSH
uses: webfactory/ssh-agent@v0.5.3
with:
ssh-private-key: ${{ secrets.SSH_KEY }}
- name: Copy files to server
run: |
scp -o StrictHostKeyChecking=no docker-compose.yml Dockerfile ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:/home/${{ secrets.SSH_USER }}/munera/
scp -o StrictHostKeyChecking=no target/munera-1.0-SNAPSHOT.jar ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:/home/${{ secrets.SSH_USER }}/munera/
- name: Deploy on server
run: |
ssh -o StrictHostKeyChecking=no ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} << 'EOF'
cd /home/${{ secrets.SSH_USER }}/munera
echo "DB_ADDRESS=${DB_ADDRESS}" > .env
echo "DB_USER=${DB_USER}" >> .env
echo "DB_PASSWORD=${DB_PASSWORD}" >> .env
echo "DB_NAME=${DB_NAME}" >> .env
docker-compose down
docker-compose up -d --build
EOF
env:
DB_ADDRESS: ${{ secrets.DB_ADDRESS }}
DB_USER: ${{ secrets.DB_USER }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
DB_NAME: ${{ secrets.DB_NAME }}

View file

@ -1,13 +1,27 @@
# Use a Maven or Gradle image to build the JAR
FROM maven:3.8.5-openjdk-21-slim AS build
# Set the working directory
WORKDIR /app
# Copy the source code into the container
COPY . .
# Build the JAR file
RUN mvn clean package -DskipTests
# Use a lightweight image to run the JAR
FROM openjdk:21-jdk-slim FROM openjdk:21-jdk-slim
# Set the working directory # Set the working directory
WORKDIR /app WORKDIR /app
# Copy the JAR file into the container # Copy the JAR file from the build stage
COPY target/munera-1.0-SNAPSHOT.jar /app/munera-1.0-SNAPSHOT.jar COPY --from=build /app/target/munera-1.0-SNAPSHOT.jar /app/munera-1.0-SNAPSHOT.jar
# Expose the port the app runs on # Expose the port the app runs on
EXPOSE 8080 EXPOSE 8080
# Run the JAR file # Run the JAR file
CMD ["java", "-jar", "/app/munera-1.0-SNAPSHOT.jar"] CMD ["java", "-jar", "/app/munera-1.0-SNAPSHOT.jar"]