Skip to content

Commit 2da7d98

Browse files
committed
chore: wip
1 parent 516a337 commit 2da7d98

File tree

4 files changed

+46
-8
lines changed

4 files changed

+46
-8
lines changed

storage/framework/server/.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
bootstrap
2+
*bun-build
3+
Actions
4+
app
5+
config
6+
core
7+
docs
8+
routes
9+
server
10+
storage
11+
env.ts
12+
cdk.context.json
13+
cdk.out

storage/framework/server/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ This directory is used to store files to build the Docker image for the server.
88

99
## Notes
1010

11-
We use a custom `tsconfig.json` file to ensure that the aliases point to the correct paths.
11+
We use a custom `tsconfig.json` file to ensure that the aliases point to the correct paths within the Docker image.
1212

1313
### TODO
1414

15-
- [ ] Don't include node_modules in the Docker image, but bundle it using Bun
16-
- [ ] Include bun.lockb file to build the Docker image && the `--frozen-lockfile` flag
15+
- [ ] Don't include `node_modules` in the Docker image, but bundle it using Bun
1716
- [ ] Ensure to use workspaces in the `package.json` file
1817
- [ ] No need for ./Actions because ./app/Actions

storage/framework/server/build.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,31 @@
11
import process from 'node:process'
22
import { log } from '@stacksjs/cli'
33
import { cloud } from '@stacksjs/config'
4+
import { intro, outro } from '../core/build/src'
45
import { buildDockerImage, useCustomOrDefaultServerConfig } from './src/utils'
56

67
async function main() {
8+
const { startTime } = await intro({
9+
dir: import.meta.dir,
10+
})
11+
12+
const result = await Bun.build({
13+
entrypoints: ['./src/index.ts'],
14+
outdir: './dist',
15+
format: 'esm',
16+
target: 'bun',
17+
})
18+
719
await useCustomOrDefaultServerConfig()
820

921
if (cloud.api?.deploy)
1022
await buildDockerImage()
23+
24+
await outro({
25+
dir: import.meta.dir,
26+
startTime,
27+
result,
28+
})
1129
}
1230

1331
main().catch((error) => {

storage/framework/server/src/utils.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import process from 'node:process'
2-
import { log, runCommand } from '@stacksjs/cli'
2+
import { log } from '@stacksjs/cli'
33
import { app } from '@stacksjs/config'
44
import { frameworkCloudPath, frameworkPath, projectPath } from '@stacksjs/path'
55
import { hasFiles } from '@stacksjs/storage'
@@ -8,8 +8,11 @@ import { $ } from 'bun'
88

99
export async function cleanCopy(sourcePath: string, targetPath: string) {
1010
$.cwd(frameworkPath('server'))
11+
log.debug(`Deleting ${targetPath} ...`)
1112
await $`rm -rf ${targetPath}`.text()
13+
log.debug(`Copying ${sourcePath} to ${targetPath} ...`)
1214
await $`cp -r ${sourcePath} ${targetPath}`.text()
15+
log.debug(`Done copying ${sourcePath} to ${targetPath}`)
1316
}
1417

1518
export async function useCustomOrDefaultServerConfig() {
@@ -29,10 +32,14 @@ export async function buildDockerImage() {
2932
log.info('Preparing build...')
3033

3134
// delete old CDK relating files, to always build fresh
32-
await $`rm -rf ${frameworkCloudPath('cdk.out/')}`
33-
await $`rm -rf ${frameworkCloudPath('cdk.context.json')}`
34-
await $`rm -rf ${frameworkCloudPath('dist.zip')}`
35+
log.debug('Deleting old CDK files...')
36+
await $`rm -rf ${frameworkCloudPath('cdk.out/')}`.text()
37+
log.debug('Deleting old CDK context file...')
38+
await $`rm -rf ${frameworkCloudPath('cdk.context.json')}`.text()
39+
log.debug('Deleting old dist.zip file...')
40+
await $`rm -rf ${frameworkCloudPath('dist.zip')}`.text()
3541

42+
log.info('Copying project files...')
3643
await cleanCopy(projectPath('config'), frameworkPath('server/config'))
3744
await cleanCopy(projectPath('routes'), frameworkPath('server/routes'))
3845
await cleanCopy(projectPath('app'), frameworkPath('server/app'))
@@ -45,7 +52,8 @@ export async function buildDockerImage() {
4552
}
4653

4754
$.cwd(frameworkPath('server'))
48-
// TODO: need to build index.ts into index.js and then run that from within the Dockerfile
55+
56+
// build index.ts into index.js, to then use within the Dockerfile
4957
await $`bun run build`.text()
5058

5159
// this currently does not need to be enabled because our CDK deployment handles the docker build process

0 commit comments

Comments
 (0)