Skip to content

Commit

Permalink
feat(hcdc-access-service): integrate S3 configuration and update prin…
Browse files Browse the repository at this point in the history
…t templates to use new logo source
  • Loading branch information
wermarter committed Dec 22, 2024
1 parent 53aae13 commit 7b422d6
Show file tree
Hide file tree
Showing 25 changed files with 133 additions and 119 deletions.
Binary file added apps/hcdc-access-service/assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<div class="flex flex-col justify-between">
<div class="flex flex-row">
<img
src=<%= `http://${process.env.MINIO_ENDPOINT}:${process.env.MINIO_PORT}/${process.env.MINIO_PUBLIC_BUCKET}/logo.png` %>
src=<%= `https://raw.githubusercontent.com/wermarter/diut/refs/heads/main/apps/hcdc-access-service/assets/logo.png` %>
style="width: 90px; object-fit: contain"
/>
<div class="text-center ml-1 text-base">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<div class="flex flex-row justify-between">
<div class="flex flex-row">
<img
src=<%= `http://${process.env.MINIO_ENDPOINT}:${process.env.MINIO_PORT}/${process.env.MINIO_PUBLIC_BUCKET}/logo.png` %>
src=<%= `https://raw.githubusercontent.com/wermarter/diut/refs/heads/main/apps/hcdc-access-service/assets/logo.png` %>
style="width: 90px; object-fit: contain"
/>
<div class="text-center ml-1">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<!-- -------------------------------------------------------------- -->
<div class="flex flex-row gap-1">
<img
src=<%= `http://${process.env.MINIO_ENDPOINT}:${process.env.MINIO_PORT}/${process.env.MINIO_PUBLIC_BUCKET}/logo.png` %>
src=<%= `https://raw.githubusercontent.com/wermarter/diut/refs/heads/main/apps/hcdc-access-service/assets/logo.png` %>
style="width: 90px; object-fit: contain"
/>
<div class="text-left ml-1 text-base">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<div class="flex flex-row justify-between">
<div class="flex flex-row">
<img
src=<%= `http://${process.env.MINIO_ENDPOINT}:${process.env.MINIO_PORT}/${process.env.MINIO_PUBLIC_BUCKET}/logo.png` %>
src=<%= `https://raw.githubusercontent.com/wermarter/diut/refs/heads/main/apps/hcdc-access-service/assets/logo.png` %>
style="width: 90px; object-fit: contain"
/>
<div class="text-center ml-1 text-base">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<div class="flex flex-col">
<div class="flex flex-row">
<img
src=<%= `http://${process.env.MINIO_ENDPOINT}:${process.env.MINIO_PORT}/${process.env.MINIO_PUBLIC_BUCKET}/logo.png` %>
src=<%= `https://raw.githubusercontent.com/wermarter/diut/refs/heads/main/apps/hcdc-access-service/assets/logo.png` %>
style="width: 90px; object-fit: contain"
/>
<div class="text-center ml-1 text-base">
Expand Down
2 changes: 1 addition & 1 deletion apps/hcdc-access-service/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export * from './module'
export * from './app'
export * from './auth'
export * from './client'
export * from './minio'
export * from './mongo'
export * from './redis'
export * from './s3'
export * from './telemetry'
46 changes: 0 additions & 46 deletions apps/hcdc-access-service/src/config/minio.ts

This file was deleted.

4 changes: 2 additions & 2 deletions apps/hcdc-access-service/src/config/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { ModuleMetadata } from '@nestjs/common'
import { loadAppConfig } from './app'
import { loadAuthConfig } from './auth'
import { loadClientConfig } from './client'
import { loadMinioConfig } from './minio'
import { loadMongoConfig } from './mongo'
import { loadRedisConfig } from './redis'
import { loadS3Config } from './s3'
import { loadTelemetryConfig } from './telemetry'

export const configMetadata: ModuleMetadata = {
Expand All @@ -16,7 +16,7 @@ export const configMetadata: ModuleMetadata = {
loadAppConfig,
loadAuthConfig,
loadClientConfig,
loadMinioConfig,
loadS3Config,
loadMongoConfig,
loadRedisConfig,
loadTelemetryConfig,
Expand Down
32 changes: 32 additions & 0 deletions apps/hcdc-access-service/src/config/s3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { makeConfigLoader } from '@diut/nestjs-infra'
import { Expose } from 'class-transformer'
import { IsString, MinLength } from 'class-validator'

export class S3Config {
@Expose()
@MinLength(1)
@IsString()
S3_ACCESS_KEY: string

@Expose()
@MinLength(1)
@IsString()
S3_SECRET_KEY: string

@Expose()
@MinLength(1)
@IsString()
S3_REGION: string

@Expose()
@MinLength(1)
@IsString()
S3_SAMPLE_IMAGES_BUCKET: string

@Expose()
@MinLength(1)
@IsString()
S3_APP_BUCKET: string
}

export const loadS3Config = makeConfigLoader(S3Config)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ export const STORAGE_BUCKET_TOKEN = Symbol('STORAGE_BUCKET_TOKEN')

export enum StorageBucket {
APP = 'APP',
PUBLIC = 'PUBLIC',
SAMPLE_IMAGES = 'SAMPLE_IMAGES',
}

Expand All @@ -11,7 +10,6 @@ export interface IStorageBucket {
}

export const StorageKeyFactory = {
[StorageBucket.PUBLIC]: {},
[StorageBucket.APP]: {
printFormTemplate(input: { templatePath: string }) {
return `print-template/${input.templatePath}`
Expand Down
36 changes: 0 additions & 36 deletions apps/hcdc-access-service/src/infra/minio/module.ts

This file was deleted.

4 changes: 2 additions & 2 deletions apps/hcdc-access-service/src/infra/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import { concatModuleMetadata } from '@diut/nestjs-infra'
import { JwtModule } from '@nestjs/jwt'
import { browserServiceMetadata } from './browser-service'
import { clsMetadata } from './cls'
import { minioMetadata } from './minio'
import { mongoMetadata } from './mongo'
import { pinoMetadata } from './pino'
import { redisMetadata } from './redis'
import { s3Metadata } from './s3'

export const infraMetadata = concatModuleMetadata([
{ imports: [JwtModule.register({})] },
clsMetadata,
pinoMetadata,
minioMetadata,
s3Metadata,
redisMetadata,
mongoMetadata,
browserServiceMetadata,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { stringEnumValues } from '@diut/common'
import { Inject, Injectable, Logger, OnModuleInit } from '@nestjs/common'
import { MinioConfig, loadMinioConfig } from 'src/config'
import { S3Config, loadS3Config } from 'src/config'
import {
IStorageBucket,
IStorageService,
Expand All @@ -13,32 +13,36 @@ export class StorageBucketProvider implements IStorageBucket, OnModuleInit {
private logger = new Logger(this.constructor.name)

constructor(
@Inject(loadMinioConfig.KEY) private readonly minioConfig: MinioConfig,
@Inject(loadS3Config.KEY) private readonly s3Config: S3Config,
@Inject(STORAGE_SERVICE_TOKEN)
private readonly storageService: IStorageService,
) {}

get(key: StorageBucket): string {
switch (key) {
case StorageBucket.APP:
return this.minioConfig.MINIO_APP_BUCKET
case StorageBucket.PUBLIC:
return this.minioConfig.MINIO_PUBLIC_BUCKET
return this.s3Config.S3_APP_BUCKET
case StorageBucket.SAMPLE_IMAGES:
return this.minioConfig.MINIO_SAMPLE_IMAGES_BUCKET
return this.s3Config.S3_SAMPLE_IMAGES_BUCKET
default:
throw new Error('Invalid storage bucket')
}
}

async onModuleInit() {
for (const bucketId of stringEnumValues(StorageBucket)) {
const bucket = this.get(bucketId as StorageBucket)
try {
for (const bucketId of stringEnumValues(StorageBucket)) {
const bucket = this.get(bucketId as StorageBucket)

const isExisted = await this.storageService.assertBucket(bucket)
if (!isExisted) {
this.logger.verbose(`Bucket "${bucket}" created`)
const isExisted = await this.storageService.assertBucket(bucket)
if (!isExisted) {
this.logger.verbose(`Bucket "${bucket}" created`)
}
}
} catch (error) {
process.nextTick(() => {
throw error
})
}
}
}
34 changes: 34 additions & 0 deletions apps/hcdc-access-service/src/infra/s3/module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { AwsS3ClientModule, getAwsS3ServiceToken } from '@diut/nestjs-infra'
import { ModuleMetadata } from '@nestjs/common'
import { S3Config, loadS3Config } from 'src/config'
import { STORAGE_BUCKET_TOKEN, STORAGE_SERVICE_TOKEN } from 'src/domain'
import { StorageBucketProvider } from './bucket'

const S3_INSTANCE_ID = 'S3'

export const s3Metadata: ModuleMetadata = {
imports: [
AwsS3ClientModule.registerAsync({
instanceId: S3_INSTANCE_ID,
inject: [loadS3Config.KEY],
useFactory: async (s3Config: S3Config) => ({
bucketName: s3Config.S3_SAMPLE_IMAGES_BUCKET,
region: s3Config.S3_REGION,
credentials: {
accessKeyId: s3Config.S3_ACCESS_KEY,
secretAccessKey: s3Config.S3_SECRET_KEY,
},
}),
}),
],
providers: [
{
provide: STORAGE_SERVICE_TOKEN,
useExisting: getAwsS3ServiceToken(S3_INSTANCE_ID),
},
{
provide: STORAGE_BUCKET_TOKEN,
useClass: StorageBucketProvider,
},
],
}
1 change: 1 addition & 0 deletions apps/hcdc-web-app/src/infra/api/access-service/sample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ const injectedRtkApi = api
url: `/api/v1/samples/print`,
method: 'POST',
body: queryArg,
responseHandler: fileReponseHandler({ mode: 'preview' }),
}),
invalidatesTags: ['samples'],
}),
Expand Down
12 changes: 11 additions & 1 deletion k8s/setup/install-requirement.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@ sudo apt-add-repository ppa:ansible/ansible
sudo apt update && sudo apt upgrade -y
sudo apt install ansible ansible-lint

ssh-keygen -f ~/.ssh/labo2
ssh-keygen -f ~/.ssh/labo3
ssh-keygen -f ~/.ssh/labo4
ssh-keygen -f ~/.ssh/labo5

echo "Host labo3
echo "
Host labo2
HostName 10.1.1.97
User werma
Port 32
IdentityFile ~/.ssh/labo2
AddKeysToAgent yes
Host labo3
User werma
Port 957
IdentityFile ~/.ssh/labo3
Expand All @@ -27,10 +35,12 @@ Host labo5
IdentityFile ~/.ssh/labo5
AddKeysToAgent yes" > ~/.ssh/config

ssh-copy-id -i ~/.ssh/labo2.pub werma@labo2
ssh-copy-id -i ~/.ssh/labo3.pub werma@labo3
ssh-copy-id -i ~/.ssh/labo4.pub werma@labo4
ssh-copy-id -i ~/.ssh/labo5.pub werma@labo5

ssh labo2
ssh labo3
ssh labo4
ssh labo5
Expand Down
1 change: 1 addition & 0 deletions k8s/setup/inventory.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ hcdc-lab:
labo3:
labo4:
labo5:
labo2:
1 change: 1 addition & 0 deletions k8s/setup/k3s-ansible-config/hosts.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ labo4
labo5

[node]
labo2

# only required if proxmox_lxc_configure: true
# must contain all proxmox instances that have a master or worker node
Expand Down
6 changes: 6 additions & 0 deletions k8s/setup/playbooks/prepare-longhorn.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
- name: Longhorn requirement
hosts: all
become: true
tasks:
- name: Ensure nfs-common are installed
ansible.builtin.package:
name: nfs-common
state: present

- name: Append blacklist block to /etc/multipath.conf
blockinfile:
path: /etc/multipath.conf
Expand Down
Loading

0 comments on commit 7b422d6

Please sign in to comment.