Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/backend/enhancement/annotation-s…
Browse files Browse the repository at this point in the history
…ervice-impl' into backend/enhancement/annotation-service-impl
  • Loading branch information
emresin12 committed Dec 24, 2023
2 parents cdd404d + 1aaaaef commit a61f24a
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 3 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/annotation_build.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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 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 }}"
29 changes: 29 additions & 0 deletions app/annotation-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 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


# Set the script to be executable
RUN chmod +x ./gradlew

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 8080
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"]
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit a61f24a

Please sign in to comment.