forked from dagger/dagger
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix .mjs docs lint and format (dagger#5435)
Signed-off-by: Helder Correia <174525+helderco@users.noreply.github.com>
- Loading branch information
Showing
29 changed files
with
1,026 additions
and
888 deletions.
There are no files selected for viewing
30 changes: 16 additions & 14 deletions
30
docs/current/cookbook/snippets/cache-invalidation/index.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,20 @@ | ||
import { connect } from "@dagger.io/dagger" | ||
|
||
// create Dagger client | ||
connect(async (client) => { | ||
connect( | ||
async (client) => { | ||
// invalidate cache to force execution | ||
// of second withExec() operation | ||
const output = await client | ||
.pipeline("test") | ||
.container() | ||
.from("alpine") | ||
.withExec(["apk", "add", "curl"]) | ||
.withEnvVariable("CACHEBUSTER", Date.now().toString()) | ||
.withExec(["apk", "add", "zip"]) | ||
.stdout() | ||
|
||
// invalidate cache to force execution | ||
// of second withExec() operation | ||
const output = await client.pipeline("test"). | ||
container(). | ||
from("alpine"). | ||
withExec(["apk", "add", "curl"]). | ||
withEnvVariable("CACHEBUSTER", Date.now().toString()). | ||
withExec(["apk", "add", "zip"]). | ||
stdout() | ||
|
||
console.log(output) | ||
|
||
}, {LogOutput: process.stderr}) | ||
console.log(output) | ||
}, | ||
{ LogOutput: process.stderr } | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,34 @@ | ||
import { connect } from "@dagger.io/dagger" | ||
|
||
// create Dagger client | ||
connect(async (client) => { | ||
// define tags | ||
const tags = ["latest", "1.0-alpine", "1.0", "1.0.0"] | ||
connect( | ||
async (client) => { | ||
// define tags | ||
const tags = ["latest", "1.0-alpine", "1.0", "1.0.0"] | ||
|
||
if(!process.env.DOCKERHUB_USERNAME) { | ||
console.log('DOCKERHUB_USERNAME environment variable must be set'); | ||
process.exit(); | ||
} | ||
if(!process.env.DOCKERHUB_PASSWORD) { | ||
console.log('DOCKERHUB_PASSWORD environment variable must be set'); | ||
process.exit(); | ||
} | ||
const username = process.env.DOCKERHUB_USERNAME; | ||
const password = process.env.DOCKERHUB_PASSWORD; | ||
if (!process.env.DOCKERHUB_USERNAME) { | ||
console.log("DOCKERHUB_USERNAME environment variable must be set") | ||
process.exit() | ||
} | ||
if (!process.env.DOCKERHUB_PASSWORD) { | ||
console.log("DOCKERHUB_PASSWORD environment variable must be set") | ||
process.exit() | ||
} | ||
const username = process.env.DOCKERHUB_USERNAME | ||
const password = process.env.DOCKERHUB_PASSWORD | ||
|
||
// set secret as string value | ||
const secret = client.setSecret("password", password); | ||
// set secret as string value | ||
const secret = client.setSecret("password", password) | ||
|
||
// create and publish image with multiple tags | ||
const container = client.container(). | ||
from("alpine") | ||
// create and publish image with multiple tags | ||
const container = client.container().from("alpine") | ||
|
||
for (var tag in tags) { | ||
let addr = await container. | ||
withRegistryAuth("docker.io", username, secret). | ||
publish(`${username}/my-alpine:${tags[tag]}`) | ||
console.log(`Published at: ${addr}`) | ||
} | ||
|
||
}, {LogOutput: process.stderr}) | ||
for (var tag in tags) { | ||
let addr = await container | ||
.withRegistryAuth("docker.io", username, secret) | ||
.publish(`${username}/my-alpine:${tags[tag]}`) | ||
console.log(`Published at: ${addr}`) | ||
} | ||
}, | ||
{ LogOutput: process.stderr } | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,24 @@ | ||
import { connect } from "@dagger.io/dagger" | ||
|
||
// create Dagger client | ||
connect(async (client) => { | ||
connect( | ||
async (client) => { | ||
// create and publish image with annotations | ||
const container = client | ||
.container() | ||
.from("alpine") | ||
.withLabel("org.opencontainers.image.title", "my-alpine") | ||
.withLabel("org.opencontainers.image.version", "1.0") | ||
.withLabel("org.opencontainers.image.created", new Date()) | ||
.WithLabel( | ||
"org.opencontainers.image.source", | ||
"https://github.com/alpinelinux/docker-alpine" | ||
) | ||
.WithLabel("org.opencontainers.image.licenses", "MIT") | ||
|
||
// create and publish image with annotations | ||
const container = client.container(). | ||
from("alpine"). | ||
withLabel("org.opencontainers.image.title", "my-alpine"). | ||
withLabel("org.opencontainers.image.version", "1.0"). | ||
withLabel("org.opencontainers.image.created", new Date()). | ||
WithLabel("org.opencontainers.image.source", "https://github.com/alpinelinux/docker-alpine"). | ||
WithLabel("org.opencontainers.image.licenses", "MIT") | ||
const addr = await container.publish("ttl.sh/my-alpine") | ||
|
||
const addr = await container.publish("ttl.sh/my-alpine") | ||
|
||
console.log(addr) | ||
|
||
}, {LogOutput: process.stderr}) | ||
console.log(addr) | ||
}, | ||
{ LogOutput: process.stderr } | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 48 additions & 40 deletions
88
docs/current/guides/snippets/aws-codebuild-codepipeline/index.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,54 @@ | ||
import { connect } from "@dagger.io/dagger" | ||
|
||
// check for required variables in host environment | ||
const vars = ["REGISTRY_ADDRESS", "REGISTRY_USERNAME", "REGISTRY_PASSWORD"]; | ||
vars.forEach(v => { | ||
if(!process.env[v]) { | ||
console.log(`${v} variable must be set`); | ||
process.exit(); | ||
const vars = ["REGISTRY_ADDRESS", "REGISTRY_USERNAME", "REGISTRY_PASSWORD"] | ||
vars.forEach((v) => { | ||
if (!process.env[v]) { | ||
console.log(`${v} variable must be set`) | ||
process.exit() | ||
} | ||
}); | ||
}) | ||
|
||
// initialize Dagger client | ||
connect(async (client) => { | ||
|
||
// set registry password as Dagger secret | ||
const secret = client.setSecret("password", process.env.REGISTRY_PASSWORD); | ||
|
||
// get reference to the project directory | ||
const source = client.host().directory(".", { exclude: ["node_modules/", "ci/"] }); | ||
|
||
// use a node:18-slim container | ||
const node = client.container({ platform: "linux/amd64" }) | ||
.from("node:18-slim") | ||
|
||
// mount the project directory | ||
// at /src in the container | ||
// set the working directory in the container | ||
// install application dependencies | ||
// build application | ||
// set default arguments | ||
const app = node | ||
.withDirectory('/src', source) | ||
.withWorkdir("/src") | ||
.withExec(["npm", "install"]) | ||
.withExec(["npm", "run", "build"]) | ||
.withDefaultArgs({args: ["npm", "start"]}) | ||
|
||
// publish image to registry | ||
// at registry path [registry-username]/myapp | ||
// print image address | ||
const address = await app | ||
.withRegistryAuth(process.env.REGISTRY_ADDRESS, process.env.REGISTRY_USERNAME, secret) | ||
.publish(`${process.env.REGISTRY_USERNAME}/myapp`); | ||
console.log(`Published image to: ${address}`) | ||
|
||
}, { LogOutput: process.stdout }) | ||
connect( | ||
async (client) => { | ||
// set registry password as Dagger secret | ||
const secret = client.setSecret("password", process.env.REGISTRY_PASSWORD) | ||
|
||
// get reference to the project directory | ||
const source = client | ||
.host() | ||
.directory(".", { exclude: ["node_modules/", "ci/"] }) | ||
|
||
// use a node:18-slim container | ||
const node = client | ||
.container({ platform: "linux/amd64" }) | ||
.from("node:18-slim") | ||
|
||
// mount the project directory | ||
// at /src in the container | ||
// set the working directory in the container | ||
// install application dependencies | ||
// build application | ||
// set default arguments | ||
const app = node | ||
.withDirectory("/src", source) | ||
.withWorkdir("/src") | ||
.withExec(["npm", "install"]) | ||
.withExec(["npm", "run", "build"]) | ||
.withDefaultArgs({ args: ["npm", "start"] }) | ||
|
||
// publish image to registry | ||
// at registry path [registry-username]/myapp | ||
// print image address | ||
const address = await app | ||
.withRegistryAuth( | ||
process.env.REGISTRY_ADDRESS, | ||
process.env.REGISTRY_USERNAME, | ||
secret | ||
) | ||
.publish(`${process.env.REGISTRY_USERNAME}/myapp`) | ||
console.log(`Published image to: ${address}`) | ||
}, | ||
{ LogOutput: process.stdout } | ||
) |
Oops, something went wrong.