Skip to content

Commit

Permalink
Merge pull request #395 from elsoul/init
Browse files Browse the repository at this point in the history
update - skeet init
  • Loading branch information
POPPIN-FUMI authored Apr 9, 2024
2 parents a18b042 + 5a8ea42 commit cbdf019
Show file tree
Hide file tree
Showing 28 changed files with 115 additions and 49 deletions.
5 changes: 5 additions & 0 deletions .changeset/modern-zebras-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@skeet-framework/cli": patch
---

Update - skeet init
8 changes: 7 additions & 1 deletion packages/cli/src/cli/ai/skeetPrompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ To successfully set up Skeet Cloud, users must progress through a series of seve
2. PROJECT_CREATED - Once the projects are created, proceed to set up your first Firebase Functions by executing the command:\n\n $ skeet deploy
3. FUNCTIONS_CREATED - After setting up Firebase Functions, the next step is to configure Github Actions for continuous integration and delivery. This is also done using the same command: $ skeet init --repo
4. GITHUB_ACTIONS_CREATED - With Github Actions configured, the following task is to establish a VPN to securely connect your resources. Use the command: $ skeet init --vpn
5. VPN_CREATED - After the VPN setup, the next milestone involves setting up Cloud SQL to manage your databases. This is accomplished with: $ skeet init
5. VPN_CREATED - After the VPN setup, the penultimate step is to create a load balancer. This is achieved by running the command: $ skeet init --lb
6. LOAD_BALANCER_CREATED - All steps are now complete, and your Skeet Cloud is operational. You have successfully set up your environment and are ready to build and deploy your applications. If you have any questions, feel free to ask me anything by running the command: $ skeet ai
It's important to follow these steps in order to properly set up and configure your Skeet Cloud environment. Ensure that you consult the provided documentation and use the specified commands as you progress through each status.
You will get a cloud status and answer what you need to do next.
Expand Down Expand Up @@ -40,6 +41,11 @@ You must provide the user with the next steps to take based on their current sta
},
{
input: 'VPN_CREATED',
output:
'Impressive!Your cloud status is VPN_CREATED.\nYour VPN is now set up. The next step is to create a load balancer. \nPlease run the command:\n\n $ skeet init --lb',
},
{
input: 'LOAD_BALANCER_CREATED',
output:
'Congratulations 🎊 Your are all set!\nYour Skeet Cloud is now operational, and you have completed all tutorials. Well done!\nPlease ask me anything by\n\n $ skeet ai',
},
Expand Down
1 change: 0 additions & 1 deletion packages/cli/src/cli/init/askQuestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export const askForNeedDomain = async () => {
}

export type DomainAnswer = {
isDomain: boolean
appDomain: string
nsDomain: string
lbDomain: string
Expand Down
5 changes: 5 additions & 0 deletions packages/cli/src/cli/init/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,28 @@ import { program } from '@/index'
import { init } from './init'
import { generanteGitRepo } from './initStep/generanteGitRepo'
import { createVPN } from './initStep/createVPN'
import { createLoadBalancer } from '@/lib'

type Options = {
repo: boolean
vpn: boolean
lb: boolean
}

export const initCommands = async () => {
program
.command('init')
.option('--repo', 'Configure Github Repo/Actions', false)
.option('--vpn', 'Setup Cloud VPN', false)
.option('--lb', 'Setup Load Balancer', false)
.description('Initialize Google Cloud Setups')
.action(async (options: Options) => {
if (options.repo) {
await generanteGitRepo()
} else if (options.vpn) {
await createVPN()
} else if (options.lb) {
await createLoadBalancer()
} else {
await init()
}
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/src/cli/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { initFirebaseProject } from './initStep/initFirebaseProject'
import { deployFirebaseFunctions } from './initStep/deployFirebaseFunctions'
import { generanteGitRepo } from './initStep/generanteGitRepo'
import { createVPN } from './initStep/createVPN'
import { createLoadBalancer } from '@/lib'

export const init = async () => {
// Initialize Firebase Project - cloudStatus: 'PROJECT_CREATED'
Expand All @@ -15,4 +16,7 @@ export const init = async () => {

// Create VPN and NAT - cloudStatus: 'VPN_CREATED'
await createVPN()

// Create Load Balancer - cloudStatus: 'LOAD_BALANCER_CREATED'
await createLoadBalancer()
}
2 changes: 2 additions & 0 deletions packages/cli/src/cli/init/initStep/deployFirebaseFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { updateSkeetCloudConfigCloudStatus } from '../../init/updateSkeetCloudCo

export const deployFirebaseFunctions = async () => {
const config = await readOrCreateConfig()
spawnSync(`pnpm install`, { shell: true, stdio: 'inherit' })
spawnSync(`pnpm -F skeet-func build`, { shell: true, stdio: 'inherit' })
const cmd1 = `firebase deploy --only functions:skeet-func:root --project ${config.app.projectId}`
spawnSync(cmd1, { shell: true, stdio: 'inherit' })
const cmd2 = `firebase functions:list --project ${config.app.projectId}`
Expand Down
38 changes: 38 additions & 0 deletions packages/cli/src/cli/init/questionList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,41 @@ export const projectQuestions = async () => {
},
]
}

const requireDomainName = (value: string) => {
if (/.+\..+/.test(value)) {
return true
}

return 'This is not Domain Name!It must be example.com'
}

export const domainQuestions = [
{
type: 'input',
name: 'appDomain',
message: "What's your domain address for App",
validate: requireDomainName,
default() {
return 'app.skeet.dev'
},
},
{
type: 'input',
name: 'nsDomain',
message: "What's your domain address for Domain Name Server",
validate: requireDomainName,
default() {
return 'skeet.dev'
},
},
{
type: 'input',
name: 'lbDomain',
message: "What's your subdomain address for Load Balancer",
validate: requireDomainName,
default() {
return 'lb.skeet.dev'
},
},
]
1 change: 0 additions & 1 deletion packages/cli/src/cli/sub/sync/syncArmors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { importConfig } from '@/lib'
import { execSync } from 'child_process'
import {
createSecurityPolicy,
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/config/skeetCloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export type SkeetCloudStatusType =
| 'FUNCTIONS_CREATED'
| 'GITHUB_ACTIONS_CREATED'
| 'VPN_CREATED'
| 'LOAD_BALANCER_CREATED'

export enum SkeetCloudStatus {
NOT_CREATED,
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/lib/cliHelp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Initialize Google Cloud Setups
Options:
--repo Configure Github Repo/Actions (default: false)
--vpn Setup Cloud VPN (default: false)
--lb Setup Load Balancer (default: false)
-h, --help display help for command
Usage: skeet login [options]
Expand Down
10 changes: 0 additions & 10 deletions packages/cli/src/lib/files/addJson.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { AiConfig, SkeetOptions } from '@/types/skeetTypes'
import { importConfig } from './importConfig'
import { readFile, writeFile } from 'fs/promises'
import { FUNCTIONS_PATH, SKEET_CONFIG_PATH } from './getSkeetConfig'
import { Logger } from '../logger'
Expand Down Expand Up @@ -60,15 +59,6 @@ export const addProjectRegionToSkeetOptions = async (
}
}

export type SkeetConfigMin = {
app: {
name: string
projectId: string
region: string
}
ai: AiConfig
}

export const addProjectRegionToSkeetConfig = async () => {
const { projectId, region } = await askForProjectIdAndRegion()
const skeetConfig: SkeetCloudConfig = defaultSkeetCloudConfig
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/lib/gcloud/armor/createSecurityPolicy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getNetworkConfig } from '@/lib/files/getSkeetConfig'
import { execAsyncCmd } from '@/lib/execAsyncCmd'
import { spawnSync } from 'node:child_process'

export const createSecurityPolicy = async (
projectId: string,
Expand All @@ -13,11 +14,11 @@ export const createSecurityPolicy = async (
'create',
securityPolicyName,
'--description',
'policy for external users',
"'policy for external users'",
'--project',
projectId,
]
await execAsyncCmd(shCmd, '.')
spawnSync(shCmd[0], shCmd.slice(1), { stdio: 'inherit', shell: true })
return true
} catch (error) {
return false
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/src/lib/gcloud/armor/initArmor.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { readOrCreateConfig } from '@/config/readOrCreateConfig'
import {
importConfig,
updateBackendSecurityPolicy,
updateSecurityPolicy,
Logger,
} from '@/lib'

export const initArmor = async () => {
try {
const config = await importConfig()
updateBackendSecurityPolicy(config.app.projectId, config.app.name)
updateSecurityPolicy(config.app.projectId, config.app.name)
const config = await readOrCreateConfig()
await updateBackendSecurityPolicy(config.app.projectId, config.app.name)
await updateSecurityPolicy(config.app.projectId, config.app.name)
Logger.success(`successfully created Cloud Armor!`)
return true
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ export const updateBackendSecurityPolicy = async (
projectId,
'--global',
]
await execAsyncCmd(shCmd)
return await execAsyncCmd(shCmd)
}
7 changes: 5 additions & 2 deletions packages/cli/src/lib/gcloud/armor/updateSecurityPolicy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { getNetworkConfig } from '@/lib/files/getSkeetConfig'
import { execAsyncCmd } from '@/lib/execAsyncCmd'

export const updateSecurityPolicy = (projectId: string, appName: string) => {
export const updateSecurityPolicy = async (
projectId: string,
appName: string,
) => {
const appConf = getNetworkConfig(projectId, appName)
const shCmd = [
'gcloud',
Expand All @@ -15,5 +18,5 @@ export const updateSecurityPolicy = (projectId: string, appName: string) => {
'--log-level=VERBOSE',
'--json-parsing=STANDARD',
]
execAsyncCmd(shCmd)
return await execAsyncCmd(shCmd)
}
3 changes: 2 additions & 1 deletion packages/cli/src/lib/gcloud/lb/addBackend.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { execAsyncCmd } from '@/lib/execAsyncCmd'
import { getFunctionInfo, getNetworkConfig } from '@/lib'
import { spawnSync } from 'node:child_process'

export const addBackend = async (
projectId: string,
Expand Down Expand Up @@ -27,5 +28,5 @@ export const addBackend = async (
'--project',
projectId,
]
return await execAsyncCmd(shCmd)
spawnSync(shCmd[0], shCmd.slice(1), { stdio: 'inherit', shell: true })
}
3 changes: 2 additions & 1 deletion packages/cli/src/lib/gcloud/lb/createBackend.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { execAsyncCmd, getFunctionInfo } from '@/lib'
import { spawnSync } from 'node:child_process'

export const createBackend = async (projectId: string, methodName: string) => {
const functionInfo = getFunctionInfo(methodName)
Expand All @@ -14,5 +15,5 @@ export const createBackend = async (projectId: string, methodName: string) => {
'--project',
projectId,
]
return await execAsyncCmd(shCmd)
spawnSync(shCmd[0], shCmd.slice(1), { stdio: 'inherit', shell: true })
}
4 changes: 2 additions & 2 deletions packages/cli/src/lib/gcloud/lb/createFr.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getNetworkConfig } from '@/lib/files/getSkeetConfig'
import { execAsyncCmd } from '@/lib/execAsyncCmd'
import { spawnSync } from 'node:child_process'

export const createFr = async (projectId: string, appName: string) => {
const appConf = getNetworkConfig(projectId, appName)
Expand All @@ -23,5 +23,5 @@ export const createFr = async (projectId: string, appName: string) => {
'--project',
projectId,
]
return await execAsyncCmd(shCmd)
spawnSync(shCmd[0], shCmd.slice(1), { stdio: 'inherit', shell: true })
}
3 changes: 2 additions & 1 deletion packages/cli/src/lib/gcloud/lb/createNeg.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { readOrCreateConfig } from '@/config/readOrCreateConfig'
import { execAsyncCmd, getFunctionInfo } from '@/lib'
import { convertToKebabCase } from '@/utils/string'
import { spawnSync } from 'node:child_process'

// This will need updates when Google Cloud Run naming changed
export const createNeg = async (
Expand Down Expand Up @@ -31,5 +32,5 @@ export const createNeg = async (
'--project',
projectId,
]
return await execAsyncCmd(shCmd)
spawnSync(shCmd[0], shCmd.slice(1), { stdio: 'inherit', shell: true })
}
4 changes: 2 additions & 2 deletions packages/cli/src/lib/gcloud/lb/createProxy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getNetworkConfig } from '@/lib/files/getSkeetConfig'
import { execAsyncCmd } from '@/lib/execAsyncCmd'
import { spawnSync } from 'node:child_process'

export const createProxy = async (projectId: string, appName: string) => {
const appConf = getNetworkConfig(projectId, appName)
Expand All @@ -16,5 +16,5 @@ export const createProxy = async (projectId: string, appName: string) => {
'--project',
projectId,
]
execAsyncCmd(shCmd)
spawnSync(shCmd[0], shCmd.slice(1), { stdio: 'inherit', shell: true })
}
8 changes: 4 additions & 4 deletions packages/cli/src/lib/gcloud/lb/createRecord.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { execAsyncCmd } from '@/lib/execAsyncCmd'
import { spawnSync } from 'node:child_process'

export const createRecord = async (
projectId: string,
Expand Down Expand Up @@ -27,7 +27,7 @@ export const createRecord = async (
'--project',
projectId,
]
execAsyncCmd(shCmd)
spawnSync(shCmd[0], shCmd.slice(1), { stdio: 'inherit', shell: true })
}

export const createCaaRecords = async (
Expand All @@ -36,7 +36,7 @@ export const createCaaRecords = async (
domain: string,
) => {
const defaultRecord = await caaSslDefaultConf(projectId, zone)
await createRecord(
return await createRecord(
projectId,
zone,
domain,
Expand All @@ -49,7 +49,7 @@ export const createCaaRecords = async (

export const caaSslDefaultConf = async (projectId: string, zone: string) => {
return {
rrdatas: '0 issue "pki.goog",0 issue "letsencrypt.org"',
rrdatas: `\'0 issue "pki.goog",0 issue "letsencrypt.org"\'`,
ttl: '300',
recordType: 'CAA',
}
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/lib/gcloud/lb/createSsl.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getNetworkConfig } from '@/lib/files/getSkeetConfig'
import { execAsyncCmd } from '@/lib/execAsyncCmd'
import { spawnSync } from 'node:child_process'

export const createSsl = async (
projectId: string,
Expand All @@ -18,5 +18,5 @@ export const createSsl = async (
'--project',
projectId,
]
execAsyncCmd(shCmd)
spawnSync(shCmd[0], shCmd.slice(1), { stdio: 'inherit', shell: true })
}
6 changes: 3 additions & 3 deletions packages/cli/src/lib/gcloud/lb/createZone.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getNetworkConfig } from '@/lib/files/getSkeetConfig'
import { execAsyncCmd } from '@/lib/execAsyncCmd'
import { spawnSync } from 'node:child_process'

export const createZone = async (
projectId: string,
Expand All @@ -18,12 +19,11 @@ export const createZone = async (
'--visibility',
'public',
'--description',
`Skeet ${domain} config`,
`\'Skeet ${domain} config\'`,
'--project',
projectId,
]
const result = await execAsyncCmd(shCmd)
return result.stdout
spawnSync(shCmd[0], shCmd.slice(1), { stdio: 'inherit', shell: true })
}

export const getZone = async (projectId: string, appName: string) => {
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/lib/gcloud/lb/updateBackend.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { execAsyncCmd, getFunctionInfo } from '@/lib'
import { getFunctionInfo } from '@/lib'
import { spawnSync } from 'node:child_process'

export const updateBackend = async (
projectId: string,
Expand All @@ -18,5 +19,5 @@ export const updateBackend = async (
'--project',
projectId,
]
return await execAsyncCmd(shCmd)
spawnSync(shCmd[0], shCmd.slice(1), { stdio: 'inherit', shell: true })
}
Loading

0 comments on commit cbdf019

Please sign in to comment.