From e7cfff83f799ee619e1726566a99e9a300140fa4 Mon Sep 17 00:00:00 2001 From: Jonas Honecker <44019407+jonashonecker@users.noreply.github.com> Date: Mon, 17 Jun 2024 14:04:34 +0200 Subject: [PATCH] Add cd pipeline (#11) --- .github/workflows/cd.yml | 90 ++++++++++++++++++++++++++++++++++++++++ Dockerfile | 4 ++ backend/pom.xml | 1 + 3 files changed, 95 insertions(+) create mode 100644 .github/workflows/cd.yml create mode 100644 Dockerfile diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 0000000..2f375f6 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,90 @@ +name: Deploy-App + +on: + push: + branches: + - main + +jobs: + build-frontend: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: '22' + + - name: Build Frontend + working-directory: frontend + run: | + npm install + npm run build + + - uses: actions/upload-artifact@v4 + with: + name: frontend-build + path: frontend/dist/ + + build-backend: + runs-on: ubuntu-latest + needs: build-frontend + steps: + - uses: actions/checkout@v4 + + - uses: actions/download-artifact@v4 + with: + name: frontend-build + path: backend/src/main/resources/static + + - name: Set up JDK + uses: actions/setup-java@v4 + with: + java-version: '22' # must match the version in the pom.xml + distribution: 'temurin' + cache: 'maven' + + - name: Build with maven + run: mvn -B package --file backend/pom.xml + + - uses: actions/upload-artifact@v4 + with: + name: ticketscout.jar + path: backend/target/ticketscout.jar # must match the finalName in the pom.xml + + push-to-docker-hub: + runs-on: ubuntu-latest + needs: build-backend + environment: production + steps: + - uses: actions/checkout@v4 + + - uses: actions/download-artifact@v4 + with: + name: ticketscout.jar + path: backend/target + + - name: Login to DockerHub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} # must match the name of the Dockerhub account + password: ${{ secrets.DOCKERHUB_PASSWORD }} # must match the password of the Dockerhub account + + - name: Build and push + uses: docker/build-push-action@v5 + with: + push: true + tags: ${{ secrets.DOCKERHUB_TAG }} # Example: username/project:latest + context: . + + deploy: + name: deploy-to-render + runs-on: ubuntu-latest + needs: push-to-docker-hub + environment: + name: production # Capstone Project name + url: https://ticketscout-latest.onrender.com/login # Link to deployment + steps: + - name: Trigger Render.com Deployment + run: | + curl -X POST ${{ secrets.RENDER_DEPLOY }} #muss mit der url des Render Deployments übereinstimmen \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c962fad --- /dev/null +++ b/Dockerfile @@ -0,0 +1,4 @@ +FROM --platform=linux/amd64 openjdk:22 +EXPOSE 8080 +ADD backend/target/ticketscout.jar ticketscout.jar +ENTRYPOINT ["java", "-jar", "ticketscout.jar"] \ No newline at end of file diff --git a/backend/pom.xml b/backend/pom.xml index 2268f1b..7f278a6 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -49,6 +49,7 @@ + ticketscout org.springframework.boot