Skip to content

Commit

Permalink
Merge branch 'develop' into fix/webapp/test
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiorodriguezgarcia committed Apr 12, 2024
2 parents 270f566 + e697941 commit 3e174b3
Show file tree
Hide file tree
Showing 14 changed files with 432 additions and 353 deletions.
286 changes: 151 additions & 135 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,135 +1,151 @@
name: Deploy on release

on:
release:
types: [published]
jobs:
unit-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 20
- uses: actions/checkout@v4
- run: npm --prefix webapp ci
- run: npm --prefix webapp test -- --coverage
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
- run: mvn clean verify
working-directory: api
env:
DATABASE_USER: ${{ secrets.DATABASE_USER }}
DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
- name: Analyze with SonarCloud
uses: sonarsource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
e2e-tests:
needs: [ unit-tests ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm --prefix webapp install
- run: npm --prefix webapp run build
- run: npm --prefix webapp run test:e2e
docker-push-api:
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 }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
with:
name: arquisoft/wiq_en2b/api
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
workdir: api
buildargs: |
DATABASE_USER
DATABASE_PASSWORD
JWT_SECRET
docker-push-webapp:
runs-on: ubuntu-latest
permissions:
contents: read
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:
REACT_APP_API_ENDPOINT: http://${{ secrets.DEPLOY_HOST }}:8080
teamname: wiq_en2b
with:
name: arquisoft/wiq_en2b/webapp
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
workdir: webapp
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, docker-push-question-generator]
steps:
- name: Deploy over SSH
uses: fifsky/ssh-action@master
env:
API_URI: ${{ secrets.DEPLOY_HOST }}
DATABASE_USER: ${{ secrets.DATABASE_USER }}
DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
with:
host: ${{ secrets.DEPLOY_HOST }}
user: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_KEY }}
command: |
wget https://raw.githubusercontent.com/arquisoft/wiq_en2b/master/docker-compose.yml -O docker-compose.yml
wget https://raw.githubusercontent.com/arquisoft/wiq_en2b/master/.env -O .env
echo "DATABASE_USER=${{ secrets.DATABASE_USER }}" >> .env
echo "DATABASE_PASSWORD=${{ secrets.DATABASE_PASSWORD }}" >> .env
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 --pull always
name: Deploy on release

on:
release:
types: [published]
jobs:
unit-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 20
- uses: actions/checkout@v4
- run: npm --prefix webapp ci
- run: npm --prefix webapp test -- --coverage
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
- run: mvn clean verify
working-directory: api
env:
DATABASE_USER: ${{ secrets.DATABASE_USER }}
DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
- name: Analyze with SonarCloud
uses: sonarsource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
e2e-tests:
needs: [ unit-tests ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm --prefix webapp install
- run: npm --prefix webapp run build
# - run: npm --prefix webapp run test:e2e
docker-push-api:
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 }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
SSL_PASSWORD: ${{ secrets.SSL_PASSWORD }}
with:
name: arquisoft/wiq_en2b/api
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
workdir: api
buildargs: |
DATABASE_USER
DATABASE_PASSWORD
JWT_SECRET
SSL_PASSWORD
docker-push-kiwiq:
runs-on: ubuntu-latest
needs: [ e2e-tests ]
steps:
- uses: actions/checkout@v4
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@v5
with:
name: arquisoft/wiq_en2b/kiwiq
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
workdir: nginx_conf
docker-push-webapp:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
needs: [ e2e-tests ]
steps:

- uses: actions/checkout@v4

- name: Create .env file
run: echo "REACT_APP_API_ENDPOINT=https://${{ secrets.DEPLOY_HOST }}:8443" > webapp/.env

- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@v5
env:
REACT_APP_API_ENDPOINT: https://${{ secrets.DEPLOY_HOST }}:8443
teamname: wiq_en2b
with:
name: arquisoft/wiq_en2b/webapp
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
workdir: webapp
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, docker-push-question-generator, docker-push-kiwiq]
steps:
- name: Deploy over SSH
uses: fifsky/ssh-action@master
env:
API_URI: ${{ secrets.DEPLOY_HOST }}
DATABASE_USER: ${{ secrets.DATABASE_USER }}
DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
with:
host: ${{ secrets.DEPLOY_HOST }}
user: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_KEY }}
command: |
wget https://raw.githubusercontent.com/arquisoft/wiq_en2b/master/docker-compose.yml -O docker-compose.yml
wget https://raw.githubusercontent.com/arquisoft/wiq_en2b/master/.env -O .env
echo "DATABASE_USER=${{ secrets.DATABASE_USER }}" >> .env
echo "DATABASE_PASSWORD=${{ secrets.DATABASE_PASSWORD }}" >> .env
echo "JWT_SECRET=${{ secrets.JWT_SECRET }}" >> .env
echo "API_URI=https://${{ secrets.DEPLOY_HOST }}:8443" >> .env
echo "SSL_PASSWORD=${{ secrets.SSL_PASSWORD }}" >> .env
docker compose --profile prod down
docker compose --profile prod up -d --pull always
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ docs/build
.idea
.vscode
.DS_Store

*.crt
*.key
*.pem
.env
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# 🧠🤔 KiWiq 🥝❓📚

Visit our page [here!!!](http://kiwiq.run.place/).

WIQ is a quiz game project inspired by the engaging and thought-provoking show "Saber y Ganar."
We aim to create a platform that not only challenges your knowledge but also sparks curiosity and the thrill of discovery.
Expand Down Expand Up @@ -48,4 +48,4 @@ Webapp | `webapp/` | Our own frontend to the backend. It is implemented in React

***

Both the backend/API and the question generator use PostgreSQL.
Both the backend/API and the question generator use PostgreSQL.
8 changes: 5 additions & 3 deletions api/src/main/java/lab/en2b/quizapi/game/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import lab.en2b.quizapi.questions.question.Question;
import lombok.*;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.util.List;

@Entity
Expand All @@ -29,7 +31,7 @@ public class Game {

private Long correctlyAnsweredQuestions = 0L;
private String language;
private LocalDateTime roundStartTime;
private Long roundStartTime = 0L;
@NonNull
private Integer roundDuration;
private boolean currentQuestionAnswered;
Expand Down Expand Up @@ -62,7 +64,7 @@ public void newRound(Question question){
setCurrentQuestionAnswered(false);
getQuestions().add(question);
increaseRound();
setRoundStartTime(LocalDateTime.now());
setRoundStartTime(Instant.now().toEpochMilli());
}

private void increaseRound(){
Expand Down Expand Up @@ -90,7 +92,7 @@ private boolean currentRoundIsOver(){
}

private boolean roundTimeHasExpired(){
return getRoundStartTime()!= null && LocalDateTime.now().isAfter(getRoundStartTime().plusSeconds(getRoundDuration()));
return getRoundStartTime()!= null && Instant.now().isAfter(Instant.ofEpochMilli(getRoundStartTime()).plusSeconds(getRoundDuration()));
}

public boolean answerQuestion(Long answerId){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;
import java.time.OffsetDateTime;

@AllArgsConstructor
@Data
Expand All @@ -34,7 +35,7 @@ public class GameResponseDto {

@Schema(description = "Moment when the timer has started", example = "LocalDateTime.now()")
@JsonProperty("round_start_time")
private LocalDateTime roundStartTime;
private String roundStartTime;

@Schema(description = "Number of seconds for the player to answer the question", example = "20")
@JsonProperty("round_duration")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.time.Instant;
import java.util.function.Function;

@Service
Expand All @@ -21,7 +22,7 @@ public GameResponseDto apply(Game game) {
.correctlyAnsweredQuestions(game.getCorrectlyAnsweredQuestions())
.actualRound(game.getActualRound())
.roundDuration(game.getRoundDuration())
.roundStartTime(game.getRoundStartTime())
.roundStartTime(game.getRoundStartTime() != null? Instant.ofEpochMilli(game.getRoundStartTime()).toString(): null)
.isGameOver(game.isGameOver())
.build();
}
Expand Down
6 changes: 6 additions & 0 deletions api/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ springdoc.api-docs.path=/swagger/api-docs

management.endpoints.web.exposure.include=prometheus
management.endpoint.prometheus.enabled=true

server.port=8443
server.ssl.key-alias=tomcat
server.ssl.key-store=/etc/letsencrypt/live/kiwiq.run.place/keystore.p12
server.ssl.key-store-type=PKCS12
server.ssl.key-store-password=${SSL_PASSWORD}
Loading

0 comments on commit 3e174b3

Please sign in to comment.