-
Notifications
You must be signed in to change notification settings - Fork 589
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Vikram Vaswani <vikram@dagger.io>
- Loading branch information
1 parent
f926c4e
commit 4d9f4f2
Showing
11 changed files
with
354 additions
and
25 deletions.
There are no files selected for viewing
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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { dag, Container, Directory, object, func } from '@dagger.io/dagger' | ||
|
||
@object() | ||
class HelloDagger { | ||
/** | ||
* Returns a directory with the production build | ||
*/ | ||
@func() | ||
build(source: Directory): Directory { | ||
return dag | ||
.container() | ||
.from('node:21-slim') | ||
.withDirectory('/src', source.withoutDirectory('dagger')) | ||
.withWorkdir('/src') | ||
.withExec(['npm', 'install']) | ||
.withExec(['npm', 'run', 'build']) | ||
.directory('./dist') | ||
} | ||
|
||
/** | ||
* Returns the result of running unit tests | ||
*/ | ||
@func() | ||
async test(source: Directory): Promise<string> { | ||
return dag | ||
.container() | ||
.from('node:21-slim') | ||
.withDirectory('/src', source.withoutDirectory('dagger')) | ||
.withWorkdir('/src') | ||
.withExec(['npm', 'install']) | ||
.withExec(['npm', 'run', 'test:unit', 'run']) | ||
.stdout() | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { dag, Container, Directory, object, func } from '@dagger.io/dagger' | ||
|
||
@object() | ||
class HelloDagger { | ||
/** | ||
* Tests, builds, packages and publishes the application | ||
*/ | ||
@func() | ||
async ci(source: Directory): Promise<string> { | ||
// run tests | ||
this.test(source) | ||
// obtain the build output directory | ||
let build = this.build(source) | ||
// create and publish a container with the build output | ||
return await this.package(build).publish('ttl.sh/myapp-' + Math.floor(Math.random() * 10000000)) | ||
} | ||
|
||
/** | ||
* Returns a container with the production build | ||
*/ | ||
@func() | ||
package(build: Directory): Container { | ||
return dag | ||
.container() | ||
.from('nginx:1.25-alpine') | ||
.withDirectory('/usr/share/nginx/html', build) | ||
.withExposedPort(80) | ||
} | ||
|
||
/** | ||
* Returns a directory with the production build | ||
*/ | ||
@func() | ||
build(source: Directory): Directory { | ||
return dag | ||
.container() | ||
.from('node:21-slim') | ||
.withDirectory('/src', source.withoutDirectory('dagger')) | ||
.withWorkdir('/src') | ||
.withExec(['npm', 'install']) | ||
.withExec(['npm', 'run', 'build']) | ||
.directory('./dist') | ||
} | ||
|
||
/** | ||
* Returns the result of running unit tests | ||
*/ | ||
@func() | ||
async test(source: Directory): Promise<string> { | ||
return dag | ||
.container() | ||
.from('node:21-slim') | ||
.withDirectory('/src', source.withoutDirectory('dagger')) | ||
.withWorkdir('/src') | ||
.withExec(['npm', 'install']) | ||
.withExec(['npm', 'run', 'test:unit', 'run']) | ||
.stdout() | ||
} | ||
} |
Oops, something went wrong.