Skip to content

Commit

Permalink
fix: create symbolic link on request to server (#564)
Browse files Browse the repository at this point in the history
  • Loading branch information
j-zimnowoda committed Sep 1, 2021
1 parent 0565fd8 commit 36f52a0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
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
21 changes: 17 additions & 4 deletions src/server/index.ts
Expand Up @@ -5,7 +5,8 @@ import { Server } from 'http'
import { commit } from '../cmd/commit'
import { validateValues } from '../cmd/validate-values'
import { decrypt, encrypt } from '../common/crypt'
import { terminal } from '../common/utils'
import { env } from '../common/envalid'
import { rootDir, terminal } from '../common/utils'

const debug = terminal('server')
const app = express()
Expand All @@ -15,6 +16,20 @@ export const stopServer = (): void => {
server?.close()
}

const symlinkEnvDir = (): void => {
const envPath = `${rootDir}/env`
if (!existsSync(env.ENV_DIR)) {
console.warn(`Values at ${env.ENV_DIR} are not mounted yet!`)
return
}
if (!existsSync(envPath)) symlinkSync(env.ENV_DIR, 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 @@ -57,10 +72,8 @@ app.get('/commit', async (req: Request, res: Response) => {
}
})

export const startServer = async (): Promise<void> => {
export const startServer = (): 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

0 comments on commit 36f52a0

Please sign in to comment.