feat: changed deploy.yml
This commit is contained in:
parent
af2b22e79c
commit
8dc1e23651
3 changed files with 87 additions and 28 deletions
30
.github/workflows/deploy.yml
vendored
30
.github/workflows/deploy.yml
vendored
|
@ -13,26 +13,30 @@ jobs:
|
|||
- name: Checkout the code
|
||||
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
|
||||
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/your-application.jar ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:/home/${{ secrets.SSH_USER }}/munera/
|
||||
|
||||
- name: Deploy on server
|
||||
- name: Deploy Docker image
|
||||
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
|
||||
docker pull vaadin-app || true
|
||||
docker stop vaadin-app || true
|
||||
docker rm vaadin-app || true
|
||||
docker run -d --name vaadin-app -p 8080:8080 \
|
||||
-e DB_ADDRESS=${DB_ADDRESS} \
|
||||
-e DB_USER=${DB_USER} \
|
||||
-e DB_PASSWORD=${DB_PASSWORD} \
|
||||
-e DB_NAME=${DB_NAME} \
|
||||
vaadin-app
|
||||
EOF
|
||||
env:
|
||||
DB_ADDRESS: ${{ secrets.DB_ADDRESS }}
|
||||
|
|
41
.github/workflows/deploy.yml.bak
vendored
Normal file
41
.github/workflows/deploy.yml.bak
vendored
Normal 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 }}
|
18
Dockerfile
18
Dockerfile
|
@ -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
|
||||
|
||||
# Set the working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Copy the JAR file into the container
|
||||
COPY target/munera-1.0-SNAPSHOT.jar /app/munera-1.0-SNAPSHOT.jar
|
||||
# Copy the JAR file from the build stage
|
||||
COPY --from=build /app/target/munera-1.0-SNAPSHOT.jar /app/munera-1.0-SNAPSHOT.jar
|
||||
|
||||
# Expose the port the app runs on
|
||||
EXPOSE 8080
|
||||
|
||||
# Run the JAR file
|
||||
CMD ["java", "-jar", "/app/munera-1.0-SNAPSHOT.jar"]
|
||||
|
||||
|
|
Loading…
Reference in a new issue