From 494c1b40122f710f6ceb3f683f306605969c6c85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20P=C3=B3=C5=82torak?= Date: Wed, 29 Nov 2023 20:57:25 +0100 Subject: [PATCH 1/2] Added actions and docker-compose --- .github/workflows/test.yml | 48 ++++++++++++++++++++++++++++++++++++++ corn-backend/Dockerfile | 8 +++++-- docker-compose.yml | 38 ++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/test.yml create mode 100644 docker-compose.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..5a40eb3e --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,48 @@ +name: Test Application with Gradle + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +permissions: + contents: read + +jobs: + test-app-with-gradle: + runs-on: ubuntu-latest + + services: + note-postgres: + image: postgres:alpine + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: none + POSTGRES_DB: noteapp + ports: + - "5100:5432" + options: --name note-postgres + steps: + - uses: actions/checkout@v4 + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + + - name: Setup Gradle + uses: gradle/gradle-build-action@v2 + env: + SPRING_DATASOURCE_URL: jdbc:postgresql://localhost:5100/noteapp + POSTGRES_USER: postgres + POSTGRES_PASSWORD: none + POSTGRES_DB: noteapp + FRONTEND_URL: http://localhost:4200 + GOOGLE_CLIENT_ID: none + GOOGLE_CLIENT_SECRET: none + with: + gradle-version: '8.2' + arguments: build + build-root-directory: note-app-backend \ No newline at end of file diff --git a/corn-backend/Dockerfile b/corn-backend/Dockerfile index 56837ab3..2e63abd6 100644 --- a/corn-backend/Dockerfile +++ b/corn-backend/Dockerfile @@ -1,6 +1,6 @@ FROM gradle:8.2-jdk17-alpine -WORKDIR /home/note-app +WORKDIR /home/todo-app COPY build.gradle . @@ -8,6 +8,10 @@ COPY settings.gradle . COPY src/ src/ +RUN gradle build -x test + +RUN mv build/libs/todo-app-backend-0.0.1-SNAPSHOT.jar todo-app.jar + EXPOSE 8080 -ENTRYPOINT ["gradle", "bootRun"] +ENTRYPOINT ["java", "-jar", "todo-app.jar"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..7af66083 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,38 @@ +version: "3.1" + +services: + corn-postgres: + container_name: corn-postgres + image: postgres:alpine + environment: + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=none + - POSTGRES_DB=corn + ports: + - "5000:5432" + corn-backend: + container_name: corn-backend + image: corn-backend + depends_on: + - corn-postgres + environment: + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=none + - POSTGRES_DB=corn + - SPRING_DATASOURCE_URL=jdbc:postgresql://corn-postgres:5432/corn + - FRONTEND_URL=corn-frontend + build: + context: corn-app-backend + dockerfile: Dockerfile + ports: + - "8080:8080" + corn-frontend: + container_name: corn-frontend + image: corn-frontend + depends_on: + - corn-backend + build: + context: corn-app-frontend + dockerfile: Dockerfile + ports: + - "4200:80" From f39b3c1c06baa2c1b2058abe460b5998bb9c49ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20P=C3=B3=C5=82torak?= Date: Wed, 29 Nov 2023 20:59:00 +0100 Subject: [PATCH 2/2] Fixed names --- .github/workflows/test.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5a40eb3e..bec2ff2b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,15 +14,15 @@ jobs: runs-on: ubuntu-latest services: - note-postgres: + corn-postgres: image: postgres:alpine env: POSTGRES_USER: postgres POSTGRES_PASSWORD: none - POSTGRES_DB: noteapp + POSTGRES_DB: corn ports: - - "5100:5432" - options: --name note-postgres + - "5000:5432" + options: --name corn-postgres steps: - uses: actions/checkout@v4 @@ -35,14 +35,14 @@ jobs: - name: Setup Gradle uses: gradle/gradle-build-action@v2 env: - SPRING_DATASOURCE_URL: jdbc:postgresql://localhost:5100/noteapp + SPRING_DATASOURCE_URL: jdbc:postgresql://localhost:5000/corn POSTGRES_USER: postgres POSTGRES_PASSWORD: none - POSTGRES_DB: noteapp + POSTGRES_DB: corn FRONTEND_URL: http://localhost:4200 GOOGLE_CLIENT_ID: none GOOGLE_CLIENT_SECRET: none with: gradle-version: '8.2' arguments: build - build-root-directory: note-app-backend \ No newline at end of file + build-root-directory: corn-backend \ No newline at end of file