-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.mts
196 lines (177 loc) · 5.95 KB
/
build.mts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import { connect, Client, Container, Directory } from '@dagger.io/dagger'
import { createRequire } from 'module'
import { env } from 'node:process'
// initialize Dagger client
connect(
async (client: Client) => {
// get reference to the local project
const source = client
.host()
.directory('.', { exclude: ['node_modules/', './docker'] })
// build docker image with dependencies
const node = client
.host()
.directory('./docker')
.dockerBuild({ dockerfile: './Dockerfile.npm' })
// identify pipeline argument passed in to determine pipeline execution
const require = createRequire(import.meta.url)
var argv = require('minimist')(process.argv.slice(2))
let pipeline
// check pipeline argument which can include string or be a boolean if left empty
// if pipeline is not defined then build execution is assumed
if ('pipeline' in argv) {
if (typeof argv['pipeline'] === 'boolean') {
pipeline = 'empty definition'
} else {
pipeline = argv['pipeline']
}
} else {
pipeline = 'build'
}
let runner
switch (pipeline) {
case 'build': {
await build(client, source, node)
break
}
case 'deployGitHubPages': {
await deployGitHubPages(client, source, node)
break
}
case 'deployFirebase': {
console.log('Deployment to Firebase currently not supported')
process.exit(1)
break
}
default: {
console.log('%s is not supported', pipeline)
process.exit(1)
}
}
},
{ LogOutput: process.stderr }
)
// run npm build along with validation of lint and test scripts
function build(client: Client, source: Directory, node: Container) {
buildPrint()
// mount cloned repository into Node image
let runner = node
.withDirectory('/src', source)
.withWorkdir('/src')
.withExec(['npm', 'install'])
// run lint
let lint = runner.withExec(['npm', 'run', 'lint'])
// run tests
let test = lint.withExec(['npm', 'run', 'test'])
test.directory('./coverage').export('./build/coverage')
// build application
// write the build output to the host
return test
.withExec(['npm', 'run', 'build:prod'])
.directory('./dist')
.export('./build/dist')
}
// deploy to github pages current build/dist location
function deployGitHubPages(client: Client, source: Directory, node: Container) {
deployPrint()
let token
// check if GitHub Token has been defined as it is a requirement to deploy
if ('GH_TOKEN' in env) {
token = client.setSecret('github-token', env['GH_TOKEN'])
} else {
console.log('GH_TOKEN is not defined in environment variables')
process.exit(1)
}
let nodeCache = client.cacheVolume('nodemodules')
// configure secret and install required modules
let runner = node
.withSecretVariable('GH_TOKEN', token)
.withDirectory('/src', source)
.withMountedCache('/src/node_modules', nodeCache)
.withWorkdir('/src')
.withExec(['npm', 'install'])
.withExec(['npm', 'run', 'build'])
// execute github pages deployment
return runner
.withExec([
'npm',
'run',
'deploy:github',
'--',
'--repo=https://github.com/jolt23/web.git',
'--name=jolt23',
])
.directory('./dist')
.export('./build/dist')
}
function buildPrint() {
console.log(' ')
console.log(' ')
console.log(' ________ ___ ___ ___ ___ ________ ')
console.log(
'|\\ __ \\ |\\ \\|\\ \\ |\\ \\ |\\ \\ |\\ ___ \\ '
)
console.log(
'\\ \\ \\|\\ /_\\ \\ \\\\\\ \\\\ \\ \\\\ \\ \\ \\ \\ \\_|\\ \\ '
)
console.log(
' \\ \\ __ \\\\ \\ \\\\\\ \\\\ \\ \\\\ \\ \\ \\ \\ \\ \\\\ \\ '
)
console.log(
' \\ \\ \\|\\ \\\\ \\ \\\\\\ \\\\ \\ \\\\ \\ \\____ \\ \\ \\_\\\\ \\ '
)
console.log(
' \\ \\_______\\\\ \\_______\\\\ \\__\\\\ \\_______\\\\ \\_______\\ '
)
console.log(' \\|_______| \\|_______| \\|__| \\|_______| \\|_______| ')
console.log(' ')
console.log(' ')
console.log('building web application ')
console.log(' ')
console.log(' ')
}
function deployPrint() {
console.log(
' '
)
console.log(
' '
)
console.log(
' ________ _______ ________ ___ ________ ___ ___ '
)
console.log(
'|\\ ___ \\ |\\ ___ \\ |\\ __ \\ |\\ \\ |\\ __ \\ |\\ \\ / /| '
)
console.log(
'\\ \\ \\_|\\ \\\\ \\ __/| \\ \\ \\|\\ \\\\ \\ \\ \\ \\ \\|\\ \\ \\ \\ \\/ / / '
)
console.log(
' \\ \\ \\ \\\\ \\\\ \\ \\_|/__\\ \\ ____\\\\ \\ \\ \\ \\ \\\\\\ \\ \\ \\ / / '
)
console.log(
' \\ \\ \\_\\\\ \\\\ \\ \\_|\\ \\\\ \\ \\___| \\ \\ \\____ \\ \\ \\\\\\ \\ \\/ / / '
)
console.log(
' \\ \\_______\\\\ \\_______\\\\ \\__\\ \\ \\_______\\\\ \\_______\\ __/ / / '
)
console.log(
' \\|_______| \\|_______| \\|__| \\|_______| \\|_______||\\___/ / '
)
console.log(
' \\|___|/ '
)
console.log(
' '
)
console.log(
'deploying web application '
)
console.log(
' '
)
console.log(
' '
)
}