Skip to content

Commit

Permalink
prøve uten blob og tester
Browse files Browse the repository at this point in the history
  • Loading branch information
Gissebass committed May 20, 2024
1 parent dbdc4c9 commit c52b4cf
Show file tree
Hide file tree
Showing 28 changed files with 885 additions and 955 deletions.
1 change: 0 additions & 1 deletion docker-compose.deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ services:
- ./static-files/:/app/static-files/
depends_on:
- postgres
- fg-blob-storage
ports:
- 8484:8080
expose:
Expand Down
15 changes: 1 addition & 14 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,4 @@ services:
ports:
- 8383:${NGINX_PORT:-80}
volumes:
- ./static-files/static/:/usr/share/nginx/html

fg-blob-storage:
container_name: hilfling-blob-storage
image: mcr.microsoft.com/azure-storage/azurite
volumes:
- ./static-files/blob_storage/:/data
restart: always
networks:
- hilfling-network
ports:
- "10000:10000"
- "10001:10001"
- "10002:10002"
- ./static-files/static/:/usr/share/nginx/html
57 changes: 28 additions & 29 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
# This file is not designed to be used a lone, but
# As an addition to './docker-compose.yml' ex: 'docker-compose -f ./docker-compose.yml -f ./docker-compose.deploy.yml up -d'
version: "3"
networks:
hilfling-network: # Used for internal networking
# # This file is not designed to be used a lone, but
# # As an addition to './docker-compose.yml' ex: 'docker-compose -f ./docker-compose.yml -f ./docker-compose.deploy.yml up -d'
# version: "3"
# networks:
# hilfling-network: # Used for internal networking

services:
run-tests:
container_name: run-tests
image: maven:3.6.3-jdk-11-slim
working_dir: /hilfling
entrypoint: mvn test
# run commands as user instead of root to avoid privilage trouble
user: "${UID}:${GID}"
volumes:
- ./:/hilfling
depends_on:
- postgres
- fg-blob-storage
expose:
- 8080
networks:
- hilfling-network
environment:
AZURE_STORAGE_CONNECTION_STRING: "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://fg-blob-storage:10000/devstoreaccount1;QueueEndpoint=http://fg-blob-storage:10001/devstoreaccount1;TableEndpoint=http://fg-blob-storage:10002/devstoreaccount1;"
DATABASE_USERNAME: $DATABASE_USERNAME
DATABASE_PASSWORD: $DATABASE_PASSWORD
DATABASE_URL: "jdbc:postgresql://postgres:5432/hilflingdb" #"jdbc:postgresql://postgres:5432/hilflingdb?createDatabaseIfNotExist=true"
# services:
# run-tests:
# container_name: run-tests
# image: maven:3.6.3-jdk-11-slim
# working_dir: /hilfling
# entrypoint: mvn test
# # run commands as user instead of root to avoid privilage trouble
# user: "${UID}:${GID}"
# volumes:
# - ./:/hilfling
# depends_on:
# - postgres
# expose:
# - 8080
# networks:
# - hilfling-network
# environment:
# AZURE_STORAGE_CONNECTION_STRING: "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://fg-blob-storage:10000/devstoreaccount1;QueueEndpoint=http://fg-blob-storage:10001/devstoreaccount1;TableEndpoint=http://fg-blob-storage:10002/devstoreaccount1;"
# DATABASE_USERNAME: $DATABASE_USERNAME
# DATABASE_PASSWORD: $DATABASE_PASSWORD
# DATABASE_URL: "jdbc:postgresql://postgres:5432/hilflingdb" #"jdbc:postgresql://postgres:5432/hilflingdb?createDatabaseIfNotExist=true"

labels:
- traefik.enable=false
# labels:
# - traefik.enable=false
15 changes: 1 addition & 14 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,4 @@ services:
ports:
- 8383:${NGINX_PORT:-80}
volumes:
- ./static-files/static/:/usr/share/nginx/html

fg-blob-storage:
container_name: hilfling-blob-storage
image: mcr.microsoft.com/azure-storage/azurite
volumes:
- ./static-files/blob_storage/:/data
restart: always
networks:
- hilfling-network
ports:
- "10000:10000"
- "10001:10001"
- "10002:10002"
- ./static-files/static/:/usr/share/nginx/html
6 changes: 1 addition & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,7 @@
<version>2.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-blob</artifactId>
<version>12.14.3</version>
</dependency>



<dependency>
Expand Down
14 changes: 0 additions & 14 deletions src/main/kotlin/no/fg/hilflingbackend/MockDataService.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package no.fg.hilflingbackend

import com.azure.storage.blob.models.PublicAccessType
import me.liuwj.ktorm.database.Database
import me.liuwj.ktorm.dsl.batchInsert
import no.fg.hilflingbackend.blobStorage.AzureBlobStorage
import no.fg.hilflingbackend.controller.PhotoController
import no.fg.hilflingbackend.dto.AlbumDto
import no.fg.hilflingbackend.dto.AlbumId
Expand Down Expand Up @@ -113,16 +110,6 @@ class MockDataService {
@Autowired
lateinit var photoRepository: PhotoRepository

@Autowired
lateinit var azureBlobStorage: AzureBlobStorage

fun initializeAzureBlobStorageContainers() {
listOf("alle", "fggjeng", "husfolk").forEach {
val containerClient = azureBlobStorage.blobServiceClient.createBlobContainer(it)
containerClient.setAccessPolicy(PublicAccessType.BLOB, null)
}
}

fun generateSecurityLevelData(): List<SecurityLevelDto> =
listOf(
SecurityLevelDto(
Expand Down Expand Up @@ -449,7 +436,6 @@ class MockDataService {
}
}
}
initializeAzureBlobStorageContainers()
println("Photos Seeded")
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
package no.fg.hilflingbackend.blobStorage
// package no.fg.hilflingbackend.blobStorage

import com.azure.storage.blob.BlobServiceClient
import com.azure.storage.blob.BlobServiceClientBuilder
import no.fg.hilflingbackend.value_object.ImageFileName
import org.springframework.stereotype.Repository
import org.springframework.web.multipart.MultipartFile
// import com.azure.storage.blob.BlobServiceClient
// import com.azure.storage.blob.BlobServiceClientBuilder
// import no.fg.hilflingbackend.value_object.ImageFileName
// import org.springframework.stereotype.Repository
// import org.springframework.web.multipart.MultipartFile

@Repository
class AzureBlobStorage(val azureStorageConfiguration: AzureStorageConfiguration) : IAzureBlobStorage {
// @Repository
// class AzureBlobStorage(val azureStorageConfiguration: AzureStorageConfiguration) : IAzureBlobStorage {

val blobServiceClient: BlobServiceClient = BlobServiceClientBuilder()
.connectionString(azureStorageConfiguration.azureStorageConnectionString)
.buildClient()
// val blobServiceClient: BlobServiceClient = BlobServiceClientBuilder()
// .connectionString(azureStorageConfiguration.azureStorageConnectionString)
// .buildClient()

override fun saveFile(multipartFile: MultipartFile, blobContainerName: String, fileName: ImageFileName): String {
// Have to get a blob container client
val blobContainerClient = this.blobServiceClient.getBlobContainerClient(blobContainerName)
// Create blob client
val blobClient = blobContainerClient.getBlobClient(fileName.filename)
// Upload file
blobClient.upload(multipartFile.inputStream, multipartFile.size)
// override fun saveFile(multipartFile: MultipartFile, blobContainerName: String, fileName: ImageFileName): String {
// // Have to get a blob container client
// val blobContainerClient = this.blobServiceClient.getBlobContainerClient(blobContainerName)
// // Create blob client
// val blobClient = blobContainerClient.getBlobClient(fileName.filename)
// // Upload file
// blobClient.upload(multipartFile.inputStream, multipartFile.size)

return blobClient.blobUrl
}
}
// return blobClient.blobUrl
// }
// }
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package no.fg.hilflingbackend.blobStorage
// package no.fg.hilflingbackend.blobStorage

import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Configuration
// import org.springframework.beans.factory.annotation.Value
// import org.springframework.context.annotation.Configuration

@Configuration
data class AzureStorageConfiguration(
@Value("\${spring.azure.storage.blob-storage.connection-string}")
val azureStorageConnectionString: String
)
// @Configuration
// data class AzureStorageConfiguration(
// @Value("\${spring.azure.storage.blob-storage.connection-string}")
// val azureStorageConnectionString: String
// )
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package no.fg.hilflingbackend.blobStorage
// package no.fg.hilflingbackend.blobStorage

import no.fg.hilflingbackend.value_object.ImageFileName
import org.springframework.web.multipart.MultipartFile
// import no.fg.hilflingbackend.value_object.ImageFileName
// import org.springframework.web.multipart.MultipartFile

interface IAzureBlobStorage {
fun saveFile(file: MultipartFile, blobContainerName: String = "alle", fileName: ImageFileName): String
}
// interface IAzureBlobStorage {
// fun saveFile(file: MultipartFile, blobContainerName: String = "alle", fileName: ImageFileName): String
// }
17 changes: 2 additions & 15 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
server:
address:
address:
- ${LISTENING_IP:backend.localhost}
- ${LISTENING_IP:localhost}
port:
port:
- ${LISTENING_PORT:8000}
- 8000
error:
Expand Down Expand Up @@ -38,18 +38,6 @@ spring:
file-size-threshold: 2KB
max-file-size: 50MB
max-request-size: 60MB
azure:
tenant-id:
client:
client-id:
client-secret:
storage:
storage-id:
storage-endpoint:
container:
blob-storage:
connection-string: ${AZURE_STORAGE_CONNECTION_STRING:DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;TableEndpoint=http://127.0.0.1:10002/devstoreaccount1;}


springdoc:
api-docs:
Expand All @@ -67,7 +55,6 @@ file:
large-upload-dir: photos/large/
medium-upload-dir: photos/medium/
small-upload-dir: photos/small/

#okta: # SECURITY OKTA
# oauth2:
# issuer: https://dev-812828.okta.com/oauth2/default
Expand Down
42 changes: 21 additions & 21 deletions src/test/kotlin/no/fg/hilflingbackend/HilflingApplicationTests.kt
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
package no.fg.hilflingbackend
// package no.fg.hilflingbackend

import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import org.springframework.boot.test.context.SpringBootTest
// import org.junit.jupiter.api.AfterAll
// import org.junit.jupiter.api.BeforeAll
// import org.junit.jupiter.api.Test
// import org.junit.jupiter.api.TestInstance
// import org.springframework.boot.test.context.SpringBootTest

@SpringBootTest
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class HilflingApplicationTests {
// @SpringBootTest
// @TestInstance(TestInstance.Lifecycle.PER_CLASS)
// class HilflingApplicationTests {

@BeforeAll
fun setup() {
print(">> Setup")
}
// @BeforeAll
// fun setup() {
// print(">> Setup")
// }

@Test
fun contextLoads() {
}
// @Test
// fun contextLoads() {
// }

@AfterAll
fun teardown() {
println(">> Teardown")
}
}
// @AfterAll
// fun teardown() {
// println(">> Teardown")
// }
// }
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package no.fg.hilflingbackend.controller
// package no.fg.hilflingbackend.controller

import org.spekframework.spek2.Spek
import org.spekframework.spek2.style.specification.describe
import kotlin.test.assertEquals
// import org.spekframework.spek2.Spek
// import org.spekframework.spek2.style.specification.describe
// import kotlin.test.assertEquals

class HealthControllerSpec : Spek({
describe("GET /health") {
val healthController: HealthController = HealthController()
// class HealthControllerSpec : Spek({
// describe("GET /health") {
// val healthController: HealthController = HealthController()

assertEquals("OK!", healthController.getHealth())
}
})
// assertEquals("OK!", healthController.getHealth())
// }
// })
Loading

0 comments on commit c52b4cf

Please sign in to comment.