Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: create symbolic link on request to server #564

Merged
merged 7 commits into from Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/common/utils.ts
Expand Up @@ -299,10 +299,9 @@ export const gucci = async (
$.quote = (v) => v
try {
let processOutput: ProcessOutput
const tmplIsString = typeof tmpl === 'string'
const templateContent: string = tmplIsString ? (tmpl as string) : dump(tmpl, { lineWidth: -1 })
const templateContent: string = typeof tmpl === 'string' ? tmpl : dump(tmpl, { lineWidth: -1 })
// Cannot be a path if it wasn't a string
if (tmplIsString && existsSync(templateContent)) {
if (typeof tmpl === 'string' && existsSync(templateContent)) {
processOutput = await $`gucci -o missingkey=zero ${gucciArgs} ${templateContent}`
} else {
// input string is a go template content
Expand Down
17 changes: 15 additions & 2 deletions src/server/index.ts
Expand Up @@ -15,6 +15,21 @@ export const stopServer = (): void => {
server?.close()
}

const symlinkEnvDir = (): void => {
const repoPath = '/tmp/otomi-values'
const envPath = 'env'
if (!existsSync(repoPath)) {
console.warn(`Values at ${repoPath} are not mounted yet!`)
return
}
if (!existsSync(envPath)) symlinkSync(repoPath, envPath)
}

app.use((req, res, next) => {
symlinkEnvDir()
next()
})

app.get('/', async (req: Request, res: Response): Promise<Response<any>> => {
return res.send({ status: 'ok' })
})
Expand Down Expand Up @@ -59,8 +74,6 @@ app.get('/commit', async (req: Request, res: Response) => {

export const startServer = async (): Promise<void> => {
server = app.listen(17771, '0.0.0.0')
const k8sPath = '/tmp/otomi-values'
if (existsSync(k8sPath)) symlinkSync(k8sPath, 'env')
debug.log(`Container listening on http://0.0.0.0:17771`)
}

Expand Down