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

update #1

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 23 additions & 26 deletions env.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#!/usr/bin/env node// Author: Gross Corporation, https://github.com/grosscorporation/eb-environment-variables



const { SecretsManager } = require('@aws-sdk/client-secrets-manager');
const fs = require('fs')
const dotenv = require('dotenv')

let fs = require('fs')
try {
dotenv.config()
if (process.env.NODE_ENV === 'development') {
require('dotenv').config({ path: process.cwd() + '/.env' })
dotenv.config({ path: process.cwd() + '/.env', override: true })
}
} catch (e) {}

const IS_GITHUB_ACTION = !!process.env.GITHUB_ACTIONS
} catch (e) {
// @ts-ignore
}

const appName = process.argv.splice(2)[0] || process.env.INPUT_SLUG
const region = process.env.INPUT_REGION || 'eu-west-1'
const appName = process.argv.splice(2)[0] ?? process.env.INPUT_SLUG ?? process.env.SLUG
const region = process.env.INPUT_REGION ?? process.env.AWS_REGION ?? 'us-east-1'

const secretName = process.env.INPUT_SECRET_NAME
const releaseTag = process.env.INPUT_RELEASE_TAG || (new Date() * 1000).toString()
const secretName = process.env.INPUT_SECRET_NAME ?? process.env.SECRET_NAME
const releaseTag = process.env.INPUT_RELEASE_TAG ?? process.env.RELEASE_TAG ?? (new Date() * 1000).toString()

console.log('###############################################################')
console.log('APP_SLUG ENV ~ ', appName)
Expand Down Expand Up @@ -46,8 +46,7 @@ const client = new SecretsManager(awsConfig)
client.getSecretValue({ SecretId: secretName }, (err, data) => {
if (err) {
throw err
} else {
if ('SecretString' in data) {
} else if ('SecretString' in data) {
const secrets = JSON.parse(data.SecretString)
secrets.CURRENT_RELEASE = releaseTag

Expand All @@ -62,21 +61,19 @@ client.getSecretValue({ SecretId: secretName }, (err, data) => {
aws:elasticbeanstalk:application:environment:
${ebFile}`

if (IS_GITHUB_ACTION) {
fs.writeFileSync('./.ebextensions/options.config', ebMap, function (err) {
if (err) {
throw err
} else {
console.log('###############################################################')
console.log('GITHUB_ACTION EB ~ ', appName)
console.log('###############################################################')
}
})
}
console.log(ebMap)

fs.writeFile('./.ebextensions/options.config', ebMap, function(err, data) {
if(err) throw err
console.log(data)
})

console.log('###############################################################')
console.log('GITHUB_ACTION EB ~ ', appName)
console.log('###############################################################')
}
}
})

setTimeout(() => {}, 5000)
setTimeout(() => { }, 5000)

return 'done'