From 831ffae1de29535fdd0e5e6f6e9ca391a18109e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mustafa=20K=C3=BC=C3=A7=C3=BCk?= <44123646+mustafakucuk-dev@users.noreply.github.com> Date: Sun, 24 Dec 2023 20:26:32 +0300 Subject: [PATCH 1/5] Dockerfile and db env added --- app/annotation-service/Dockerfile | 27 +++++++++++++++++++ .../src/main/resources/application.properties | 6 ++--- 2 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 app/annotation-service/Dockerfile diff --git a/app/annotation-service/Dockerfile b/app/annotation-service/Dockerfile new file mode 100644 index 00000000..c0748e60 --- /dev/null +++ b/app/annotation-service/Dockerfile @@ -0,0 +1,27 @@ +# Build stage +FROM amazoncorretto:17-alpine3.15 AS TEMP_BUILD_IMAGE +ENV APP_HOME=/game-lounge-annotation-service/ +WORKDIR $APP_HOME +COPY . $APP_HOME + +# Copy the gradle files and wrapper +COPY build.gradle.kts settings.gradle.kts gradlew $APP_HOME +COPY gradle $APP_HOME/gradle + +RUN ./gradlew build -x test || return 0 +COPY . . +RUN ./gradlew build -x test + +# Final stage +FROM amazoncorretto:17-alpine3.15 +ENV ARTIFACT_NAME=annotation-service-0.0.1-SNAPSHOT.jar +ENV APP_HOME=/game-lounge-annotation-service/ +WORKDIR $APP_HOME +EXPOSE 6000 +RUN mkdir /annotation + +# Copy the JAR from the build stage to the final image +COPY --from=TEMP_BUILD_IMAGE $APP_HOME/build/libs/$ARTIFACT_NAME ./spring-boot-application.jar + +# Run the application +ENTRYPOINT ["java", "-jar", "spring-boot-application.jar"] diff --git a/app/annotation-service/src/main/resources/application.properties b/app/annotation-service/src/main/resources/application.properties index 696f19c3..5a0ab422 100644 --- a/app/annotation-service/src/main/resources/application.properties +++ b/app/annotation-service/src/main/resources/application.properties @@ -1,8 +1,8 @@ # Database properties -spring.datasource.url=jdbc:postgresql://localhost:5432/annotation-db -spring.datasource.username=postgres -spring.datasource.password=0000 +spring.datasource.url=${SPRING_DATASOURCE_URL} +spring.datasource.username=${SPRING_DATASOURCE_USERNAME} +spring.datasource.password=${SPRING_DATASOURCE_PASSWORD} # Hibernate properties spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect From e002c7eb15e65a141b43b9ff15846d01756d8a08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mustafa=20K=C3=BC=C3=A7=C3=BCk?= <44123646+mustafakucuk-dev@users.noreply.github.com> Date: Sun, 24 Dec 2023 20:45:42 +0300 Subject: [PATCH 2/5] Update Dockerfile --- app/annotation-service/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/annotation-service/Dockerfile b/app/annotation-service/Dockerfile index c0748e60..d7c49cbb 100644 --- a/app/annotation-service/Dockerfile +++ b/app/annotation-service/Dockerfile @@ -8,7 +8,7 @@ COPY . $APP_HOME COPY build.gradle.kts settings.gradle.kts gradlew $APP_HOME COPY gradle $APP_HOME/gradle -RUN ./gradlew build -x test || return 0 +# RUN ./gradlew build -x test || return 0 COPY . . RUN ./gradlew build -x test From 21e964a44b7c603d79f4989bd6bbc8b132ead1dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mustafa=20K=C3=BC=C3=A7=C3=BCk?= <44123646+mustafakucuk-dev@users.noreply.github.com> Date: Sun, 24 Dec 2023 21:11:48 +0300 Subject: [PATCH 3/5] Update Dockerfile --- app/annotation-service/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/annotation-service/Dockerfile b/app/annotation-service/Dockerfile index d7c49cbb..c0748e60 100644 --- a/app/annotation-service/Dockerfile +++ b/app/annotation-service/Dockerfile @@ -8,7 +8,7 @@ COPY . $APP_HOME COPY build.gradle.kts settings.gradle.kts gradlew $APP_HOME COPY gradle $APP_HOME/gradle -# RUN ./gradlew build -x test || return 0 +RUN ./gradlew build -x test || return 0 COPY . . RUN ./gradlew build -x test From 8fc5449435e5ec8351091123cf3b82468f5c13ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mustafa=20K=C3=BC=C3=A7=C3=BCk?= <44123646+mustafakucuk-dev@users.noreply.github.com> Date: Sun, 24 Dec 2023 21:54:12 +0300 Subject: [PATCH 4/5] dockerfile edited --- .github/workflows/annotation_build.yml | 46 ++++++++++++++++++++++++++ app/annotation-service/Dockerfile | 6 ++-- 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/annotation_build.yml diff --git a/.github/workflows/annotation_build.yml b/.github/workflows/annotation_build.yml new file mode 100644 index 00000000..8b735878 --- /dev/null +++ b/.github/workflows/annotation_build.yml @@ -0,0 +1,46 @@ +name: Annotation CI/CD + +on: + #workflow_dispatch: + push: + branches: [ develop ] + paths: + - 'app/annotation-service/**' + +jobs: + + build-and-push: + runs-on: ubuntu-latest + + env: + working-directory: ./app/annotation-service + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Build Docker image + working-directory: ${{env.working-directory}} + run: | + docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/gamelounge-annotation:${{ github.run_number }} . + + - name: Login to Docker Hub + run: echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin + + - name: Push Docker image + run: | + docker push ${{ secrets.DOCKERHUB_USERNAME }}/gamelounge-annotation:${{ github.run_number }} + + # SSH and Deploy to Server + - name: Setup SSH Agent + uses: webfactory/ssh-agent@v0.5.3 + with: + ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} + + - name: Deploy to Server + run: | + ssh -o StrictHostKeyChecking=no root@${{ secrets.SERVER_IP }} \ + "docker pull ${{ secrets.DOCKERHUB_USERNAME }}/gamelounge-annotation:${{ github.run_number }} && \ + docker stop gamelounge-annotation || true && \ + docker rm gamelounge-annotation || true && \ + docker run -d --name gamelounge-annotation -p 6000:6000 -e SPRING_DATASOURCE_URL="jdbc:postgresql://${{ secrets.SERVER_IP }}:5433/annotation" -e SPRING_DATASOURCE_USERNAME="annotation" -e SPRING_DATASOURCE_PASSWORD="${{ secrets.DOCKERHUB_PASSWORD }}" ${{ secrets.DOCKERHUB_USERNAME }}/gamelounge-annotation:${{ github.run_number }}" \ No newline at end of file diff --git a/app/annotation-service/Dockerfile b/app/annotation-service/Dockerfile index c0748e60..397c80a3 100644 --- a/app/annotation-service/Dockerfile +++ b/app/annotation-service/Dockerfile @@ -8,8 +8,10 @@ COPY . $APP_HOME COPY build.gradle.kts settings.gradle.kts gradlew $APP_HOME COPY gradle $APP_HOME/gradle -RUN ./gradlew build -x test || return 0 -COPY . . + +# Set the script to be executable +RUN chmod +x ./gradlew + RUN ./gradlew build -x test # Final stage From 1aaaaef784b1ce0637a04c4ab544fe3bc1898997 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mustafa=20K=C3=BC=C3=A7=C3=BCk?= <44123646+mustafakucuk-dev@users.noreply.github.com> Date: Sun, 24 Dec 2023 22:07:14 +0300 Subject: [PATCH 5/5] annotation service port edited --- .github/workflows/annotation_build.yml | 2 +- app/annotation-service/Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/annotation_build.yml b/.github/workflows/annotation_build.yml index 8b735878..0de8f936 100644 --- a/.github/workflows/annotation_build.yml +++ b/.github/workflows/annotation_build.yml @@ -43,4 +43,4 @@ jobs: "docker pull ${{ secrets.DOCKERHUB_USERNAME }}/gamelounge-annotation:${{ github.run_number }} && \ docker stop gamelounge-annotation || true && \ docker rm gamelounge-annotation || true && \ - docker run -d --name gamelounge-annotation -p 6000:6000 -e SPRING_DATASOURCE_URL="jdbc:postgresql://${{ secrets.SERVER_IP }}:5433/annotation" -e SPRING_DATASOURCE_USERNAME="annotation" -e SPRING_DATASOURCE_PASSWORD="${{ secrets.DOCKERHUB_PASSWORD }}" ${{ secrets.DOCKERHUB_USERNAME }}/gamelounge-annotation:${{ github.run_number }}" \ No newline at end of file + docker run -d --name gamelounge-annotation -p 8081:8080 -e SPRING_DATASOURCE_URL="jdbc:postgresql://${{ secrets.SERVER_IP }}:5433/annotation" -e SPRING_DATASOURCE_USERNAME="annotation" -e SPRING_DATASOURCE_PASSWORD="${{ secrets.DOCKERHUB_PASSWORD }}" ${{ secrets.DOCKERHUB_USERNAME }}/gamelounge-annotation:${{ github.run_number }}" \ No newline at end of file diff --git a/app/annotation-service/Dockerfile b/app/annotation-service/Dockerfile index 397c80a3..dbf47c86 100644 --- a/app/annotation-service/Dockerfile +++ b/app/annotation-service/Dockerfile @@ -19,7 +19,7 @@ FROM amazoncorretto:17-alpine3.15 ENV ARTIFACT_NAME=annotation-service-0.0.1-SNAPSHOT.jar ENV APP_HOME=/game-lounge-annotation-service/ WORKDIR $APP_HOME -EXPOSE 6000 +EXPOSE 8080 RUN mkdir /annotation # Copy the JAR from the build stage to the final image