diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a518bfcc..b082ddb8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,7 +3,6 @@ name: Deploy on release on: release: types: [published] - jobs: unit-tests: runs-on: ubuntu-latest @@ -60,7 +59,10 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} registry: ghcr.io workdir: api - buildargs: API_URI + buildargs: | + DATABASE_USER + DATABASE_PASSWORD + JWT_SECRET docker-push-webapp: runs-on: ubuntu-latest permissions: @@ -68,11 +70,16 @@ jobs: packages: write needs: [ e2e-tests ] steps: + - uses: actions/checkout@v4 + + - name: Create .env file + run: echo "REACT_APP_API_ENDPOINT=http://${{ secrets.DEPLOY_HOST }}:8080" > webapp/.env + - name: Publish to Registry uses: elgohr/Publish-Docker-Github-Action@v5 env: - API_URI: http://${{ secrets.DEPLOY_HOST }}:8080 + REACT_APP_API_ENDPOINT: http://${{ secrets.DEPLOY_HOST }}:8080 teamname: wiq_en2b with: name: arquisoft/wiq_en2b/webapp @@ -80,11 +87,31 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} registry: ghcr.io workdir: webapp - buildargs: API_URI + buildargs: | + REACT_APP_API_ENDPOINT + docker-push-question-generator: + runs-on: ubuntu-latest + needs: [ e2e-tests ] + steps: + - uses: actions/checkout@v4 + - name: Publish to Registry + uses: elgohr/Publish-Docker-Github-Action@v5 + env: + DATABASE_USER: ${{ secrets.DATABASE_USER }} + DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }} + with: + name: arquisoft/wiq_en2b/question-generator + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + registry: ghcr.io + workdir: questiongenerator + buildargs: | + DATABASE_USER + DATABASE_PASSWORD deploy: name: Deploy over SSH runs-on: ubuntu-latest - needs: [docker-push-api, docker-push-webapp] + needs: [docker-push-api, docker-push-webapp, docker-push-question-generator] steps: - name: Deploy over SSH uses: fifsky/ssh-action@master @@ -105,4 +132,4 @@ jobs: echo "JWT_SECRET=${{ secrets.JWT_SECRET }}" >> .env echo "API_URI=http://${{ secrets.DEPLOY_HOST }}:8080" >> .env docker compose --profile prod down - docker compose --profile prod up -d + docker compose --profile prod up -d --pull always diff --git a/README.md b/README.md index a2cf1929..b1d79d28 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,9 @@ We aim to create a platform that not only challenges your knowledge but also spa ## What Sets WIQ Apart 🤔 Thoughtful Questions: Dive into a world of intriguing and diverse questions, all generated procedurally using WikiData. -🌐 Encourage to improve: WIQ lets you keep track of your score to see in which areas you need to improve. +🌐 Encourage to improve: WIQ lets you keep track of your score to see in which areas you need to improve. + +😭 It works! after the final version final re-final (FINAL) true (final) (hotfix) ## Features 🏆 Adaptable difficulty: You can adjust the difficulty to push your limits. diff --git a/api/Dockerfile b/api/Dockerfile index 0e30a21e..878b711f 100644 --- a/api/Dockerfile +++ b/api/Dockerfile @@ -1,6 +1,5 @@ FROM maven:3.8.1-openjdk-17 AS build # Compile api -WORKDIR /api COPY . /api WORKDIR /api RUN mvn install diff --git a/api/src/main/java/lab/en2b/quizapi/questions/question/QuestionRepository.java b/api/src/main/java/lab/en2b/quizapi/questions/question/QuestionRepository.java index b07b1f8b..eb4bef47 100644 --- a/api/src/main/java/lab/en2b/quizapi/questions/question/QuestionRepository.java +++ b/api/src/main/java/lab/en2b/quizapi/questions/question/QuestionRepository.java @@ -4,6 +4,6 @@ import org.springframework.data.jpa.repository.Query; public interface QuestionRepository extends JpaRepository { - @Query(value = "SELECT q FROM questions WHERE q.language=?1 ORDER BY RANDOM() LIMIT 1", nativeQuery = true) + @Query(value = "SELECT * FROM questions WHERE language=?1 ORDER BY RANDOM() LIMIT 1", nativeQuery = true) Question findRandomQuestion(String lang); } diff --git a/docker-compose.yml b/docker-compose.yml index 2f52fd15..2b431d97 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,7 +16,7 @@ services: api: container_name: api-${teamname:-defaultASW} - image: api:latest + image: ghcr.io/arquisoft/wiq_en2b/api:latest profiles: [ "dev", "prod" ] build: context: ./api @@ -24,17 +24,39 @@ services: DATABASE_USER: ${DATABASE_USER} DATABASE_PASSWORD: ${DATABASE_PASSWORD} JWT_SECRET: ${JWT_SECRET} + environment: + - DATABASE_URL=jdbc:postgresql://WIQ_DB:5432/wiq + - DATABASE_USER=${DATABASE_USER} + - DATABASE_PASSWORD=${DATABASE_PASSWORD} + - JWT_SECRET=${JWT_SECRET} networks: - mynetwork ports: - "8080:8080" + question-generator: + container_name: question-generator-${teamname:-defaultASW} + image: ghcr.io/arquisoft/wiq_en2b/question-generator:latest + profiles: [ "dev", "prod" ] + build: + context: ./questiongenerator + args: + DATABASE_USER: ${DATABASE_USER} + DATABASE_PASSWORD: ${DATABASE_PASSWORD} + environment: + - DATABASE_URL=jdbc:postgresql://WIQ_DB:5432/wiq + - DATABASE_USER=${DATABASE_USER} + - DATABASE_PASSWORD=${DATABASE_PASSWORD} + networks: + - mynetwork + webapp: container_name: webapp-${teamname:-defaultASW} - image: webapp:latest + image: ghcr.io/arquisoft/wiq_en2b/webapp:latest profiles: [ "dev", "prod" ] - build: + args: + REACT_APP_API_ENDPOINT: ${API_URI} context: ./webapp environment: - REACT_APP_API_ENDPOINT=${API_URI} diff --git a/questiongenerator/Dockerfile b/questiongenerator/Dockerfile new file mode 100644 index 00000000..8c4e37dd --- /dev/null +++ b/questiongenerator/Dockerfile @@ -0,0 +1,19 @@ +FROM maven:3.8.1-openjdk-17 AS build +LABEL authors="dario" +# Compile api +COPY . /questiongenerator +WORKDIR /questiongenerator +RUN mvn install +RUN mvn clean package + +FROM amazoncorretto:17 AS runtime +# Copy the compiled jar file from the build stage +ARG DATABASE_USER +ARG DATABASE_PASSWORD + +# Set environment variables +ENV DATABASE_URL jdbc:postgresql://WIQ_DB:5432/wiq +ENV DATABASE_USER $DATABASE_USER +ENV DATABASE_PASSWORD $DATABASE_PASSWORD +COPY --from=build /questiongenerator/target/QuestionGenerator-1.0-SNAPSHOT-jar-with-dependencies.jar app.jar +ENTRYPOINT ["java","-jar","app.jar"] \ No newline at end of file diff --git a/questiongenerator/pom.xml b/questiongenerator/pom.xml index e1a94aa6..8317bb33 100644 --- a/questiongenerator/pom.xml +++ b/questiongenerator/pom.xml @@ -46,17 +46,49 @@ runtime 42.6.1 - + + org.apache.maven.plugins + maven-assembly-plugin + 3.4.2 + maven-plugin + org.apache.maven.plugins - maven-compiler-plugin + maven-assembly-plugin + + + jar-with-dependencies + + + + Main + + + + + + make-assembly + package + + single + + + + + + org.apache.maven.plugins + maven-jar-plugin + 3.2.0 - 11 - 11 + + + Main + +