generated from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #244 from Arquisoft/develop
Merge backend changes and deploy with https
- Loading branch information
Showing
57 changed files
with
1,637 additions
and
465 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,8 @@ docs/build | |
.idea | ||
.vscode | ||
.DS_Store | ||
|
||
*.crt | ||
*.key | ||
*.pem | ||
.env |
31 changes: 31 additions & 0 deletions
31
api/src/main/java/lab/en2b/quizapi/commons/user/UserController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package lab.en2b.quizapi.commons.user; | ||
|
||
import lab.en2b.quizapi.commons.user.dtos.UserResponseDto; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/users") | ||
@RequiredArgsConstructor | ||
public class UserController { | ||
|
||
private final UserService userService; | ||
|
||
/** | ||
* Gets the user details for the given authentication | ||
* Returns 200 if the user details are successfully retrieved | ||
* Returns 403 if the user is not logged in | ||
* @param authentication the authentication object | ||
* @return the response dto for the user details | ||
*/ | ||
@GetMapping("/details") | ||
public ResponseEntity<UserResponseDto> getUserDetails(Authentication authentication) { | ||
return ResponseEntity.ok(userService.getUserDetailsByAuthentication(authentication)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...quizapi/commons/user/UserResponseDto.java → ...pi/commons/user/dtos/UserResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
api/src/main/java/lab/en2b/quizapi/commons/user/mappers/UserResponseDtoMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.