-
Notifications
You must be signed in to change notification settings - Fork 565
/
docker.ts
50 lines (46 loc) · 1.35 KB
/
docker.ts
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
import { DeploymentConfiguration } from '../types'
import { assertGraphiQL, assertQuery, waitForEndpoint } from '../utils'
import * as docker from '@pulumi/docker'
import { interpolate } from '@pulumi/pulumi'
import { resolve } from 'path'
export const dockerDeployment = (
image: string,
): DeploymentConfiguration<{
endpoint: string
}> => ({
program: async () => {
const remoteImage = new docker.RemoteImage('node-image', {
name: image,
keepLocally: true,
})
const container = new docker.Container('container', {
image: remoteImage.repoDigest,
command: [`npx`, '.'],
volumes: [
{
containerPath: '/app',
hostPath: resolve('../'),
},
],
workingDir: '/app/packages/graphql-yoga/dist',
ports: [
{
internal: 4000,
},
],
})
// Since the provider picked a random ephemeral port for this container, export the endpoint.
const endpoint = container.ports.apply(
(ports) => `localhost:${ports![0].external}`,
)
return {
endpoint: interpolate`http://${endpoint}`,
}
},
test: async ({ endpoint }) => {
console.log(`ℹ️ Docker container deployed to URL: ${endpoint.value}`)
await waitForEndpoint(endpoint.value, 5, 10000)
await assertGraphiQL(endpoint.value)
await assertQuery(endpoint.value)
},
})