(options: BuildOptions)
| 134 | export const version = 3; |
| 135 | |
| 136 | export async function build(options: BuildOptions) { |
| 137 | const { |
| 138 | files, |
| 139 | config, |
| 140 | workPath, |
| 141 | meta = {}, |
| 142 | service, |
| 143 | registerPreDeploy, |
| 144 | } = options; |
| 145 | let { entrypoint } = options; |
| 146 | |
| 147 | const goPath = await getWriteableDirectory(); |
| 148 | const srcPath = join(goPath, 'src', 'lambda'); |
| 149 | const downloadPath = meta.skipDownload ? workPath : srcPath; |
| 150 | await download(files, downloadPath, meta); |
| 151 | |
| 152 | // keep track of file system actions we need to undo |
| 153 | // the keys "from" and "to" refer to what needs to be done |
| 154 | // in order to undo the action, not what the original action was |
| 155 | const undo: UndoActions = { |
| 156 | fileActions: [], |
| 157 | directoryCreation: [], |
| 158 | functionRenames: [], |
| 159 | }; |
| 160 | |
| 161 | const env = cloneEnv(process.env, meta.env, { |
| 162 | GOARCH: 'amd64', |
| 163 | GOOS: 'linux', |
| 164 | }); |
| 165 | |
| 166 | try { |
| 167 | if (env.GIT_CREDENTIALS) { |
| 168 | debug('Initialize Git credentials...'); |
| 169 | await initPrivateGit(env.GIT_CREDENTIALS); |
| 170 | } |
| 171 | |
| 172 | if (env.GO111MODULE) { |
| 173 | console.log(`\nManually assigning 'GO111MODULE' is not recommended. |
| 174 | |
| 175 | By default: |
| 176 | - 'GO111MODULE=on' If entrypoint package name is not 'main' |
| 177 | - 'GO111MODULE=off' If entrypoint package name is 'main' |
| 178 | |
| 179 | We highly recommend you leverage Go Modules in your project. |
| 180 | Learn more: https://github.com/golang/go/wiki/Modules |
| 181 | `); |
| 182 | } |
| 183 | |
| 184 | // Standalone server mode when framework is 'go' or 'services' |
| 185 | if (config?.framework === 'go' || config?.framework === 'services') { |
| 186 | const resolvedEntrypoint = await detectGoEntrypoint(workPath, entrypoint); |
| 187 | if (!resolvedEntrypoint) { |
| 188 | throw new Error( |
| 189 | `No Go entrypoint found. Expected one of: ${GO_CANDIDATE_ENTRYPOINTS.join(', ')}` |
| 190 | ); |
| 191 | } |
| 192 | debug(`Using standalone Go server mode for ${resolvedEntrypoint}`); |
| 193 | return buildStandaloneServer({ |
no test coverage detected