europa: vendor universe.dagger.io
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
134
pkg/universe.dagger.io/examples/changelog.com/highlevel/ci.cue
Normal file
134
pkg/universe.dagger.io/examples/changelog.com/highlevel/ci.cue
Normal file
@@ -0,0 +1,134 @@
|
||||
package ci
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
"dagger.io/dagger/engine"
|
||||
|
||||
"universe.dagger.io/docker"
|
||||
"universe.dagger.io/examples/changelog.com/highlevel/elixir/mix"
|
||||
)
|
||||
|
||||
dagger.#Plan & {
|
||||
// Receive things from client
|
||||
inputs: {
|
||||
directories: {
|
||||
// App source code
|
||||
app: _
|
||||
}
|
||||
secrets: {
|
||||
// Docker ID password
|
||||
docker: _
|
||||
}
|
||||
params: {
|
||||
// Which Elixir base image to download
|
||||
runtime_image: docker.#Ref | *"thechangelog/runtime:2021-05-29T10.17.12Z"
|
||||
// Which test DB image to download
|
||||
test_db_image: docker.#Ref | *"circleci/postgres:12.6"
|
||||
}
|
||||
}
|
||||
|
||||
// Do things
|
||||
actions: {
|
||||
// Reuse in all mix commands
|
||||
_appName: "changelog"
|
||||
|
||||
prod: assets: docker.#Build & {
|
||||
steps: [
|
||||
// 1. Start from dev assets :)
|
||||
dev.assets,
|
||||
// 2. Mix magical command
|
||||
mix.#Run & {
|
||||
script: "mix phx.digest"
|
||||
mix: {
|
||||
env: "prod"
|
||||
app: _appName
|
||||
depsCache: "readonly"
|
||||
buildCache: "readonly"
|
||||
}
|
||||
workdir: _
|
||||
// FIXME: remove copy-pasta
|
||||
mounts: nodeModules: {
|
||||
contents: engine.#CacheDir & {
|
||||
// FIXME: do we need an ID here?
|
||||
id: "\(mix.app)_assets_node_modules"
|
||||
// FIXME: does this command need write access to node_modules cache?
|
||||
concurrency: "readonly"
|
||||
}
|
||||
dest: "\(workdir)/node_modules"
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
dev: {
|
||||
build: mix.#Build & {
|
||||
env: "dev"
|
||||
app: "thechangelog"
|
||||
base: inputs.params.runtime_image
|
||||
source: inputs.directories.app.contents
|
||||
}
|
||||
|
||||
assets: docker.#Build & {
|
||||
steps: [
|
||||
// 1. Start from dev runtime build
|
||||
build,
|
||||
// 2. Build web assets
|
||||
mix.#Run & {
|
||||
mix: {
|
||||
env: "dev"
|
||||
app: _appName
|
||||
depsCache: "readonly"
|
||||
buildCache: "readonly"
|
||||
}
|
||||
// FIXME: move this to a reusable def (yarn package? or private?)
|
||||
mounts: nodeModules: {
|
||||
contents: engine.#CacheDir & {
|
||||
// FIXME: do we need an ID here?
|
||||
id: "\(mix.app)_assets_node_modules"
|
||||
// FIXME: will there be multiple writers?
|
||||
concurrency: "locked"
|
||||
}
|
||||
dest: "\(workdir)/node_modules"
|
||||
}
|
||||
// FIXME: run 'yarn install' and 'yarn run compile' separately, with different caching?
|
||||
// FIXME: can we reuse universe.dagger.io/yarn ???? 0:-)
|
||||
script: "yarn install --frozen-lockfile && yarn run compile"
|
||||
workdir: "/app/assets"
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
test: {
|
||||
build: mix.#Build & {
|
||||
env: "test"
|
||||
app: _appName
|
||||
base: inputs.params.runtime_image
|
||||
source: inputs.directories.app.contents
|
||||
}
|
||||
|
||||
// Run tests
|
||||
run: docker.#Run & {
|
||||
image: build.output
|
||||
script: "mix test"
|
||||
// Don't cache running tests
|
||||
// Just because we've tested a version before, doesn't mean we don't
|
||||
// want to test it again.
|
||||
// FIXME: make this configurable
|
||||
always: true
|
||||
}
|
||||
|
||||
db: {
|
||||
// Pull test DB image
|
||||
pull: docker.#Pull & {
|
||||
source: inputs.params.test_db_image
|
||||
}
|
||||
|
||||
// Run test DB
|
||||
// FIXME: kill once no longer needed (when tests are done running)
|
||||
run: docker.#Run & {
|
||||
image: pull.output
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,96 @@
|
||||
package mix
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
"dagger.io/dagger/engine"
|
||||
|
||||
"universe.dagger.io/docker"
|
||||
)
|
||||
|
||||
// Build an Elixir application with Mix
|
||||
#Build: {
|
||||
// Ref to base image
|
||||
// FIXME: spin out docker.#Build for max flexibility
|
||||
// Perhaps implement as a custom docker.#Build step?
|
||||
base: docker.#Ref
|
||||
|
||||
// App name (for cache scoping)
|
||||
app: string
|
||||
|
||||
// Mix environment
|
||||
env: string
|
||||
|
||||
// Application source code
|
||||
source: dagger.#FS
|
||||
|
||||
docker.#Build & {
|
||||
steps: [
|
||||
// 1. Pull base image
|
||||
docker.#Pull & {
|
||||
source: base
|
||||
},
|
||||
// 2. Copy app source
|
||||
docker.#Copy & {
|
||||
contents: source
|
||||
dest: "/app"
|
||||
},
|
||||
// 3. Download dependencies into deps cache
|
||||
#Run & {
|
||||
mix: {
|
||||
"env": env
|
||||
"app": app
|
||||
depsCache: "locked"
|
||||
}
|
||||
workdir: "/app"
|
||||
script: "mix deps.get"
|
||||
},
|
||||
// 4. Build!
|
||||
// FIXME: step 5 is to add image data, see issue 1339
|
||||
#Run & {
|
||||
mix: {
|
||||
"env": env
|
||||
"app": app
|
||||
depsCache: "private"
|
||||
buildCache: "locked"
|
||||
}
|
||||
workdir: "/app"
|
||||
script: "mix do deps.compile, compile"
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
// Run mix correctly in a container
|
||||
#Run: {
|
||||
mix: {
|
||||
app: string
|
||||
env: string
|
||||
// FIXME: "ro" | "rw"
|
||||
depsCache?: "private" | "locked"
|
||||
buildCache?: "private" | "locked"
|
||||
}
|
||||
docker.#Run
|
||||
env: MIX_ENV: mix.env
|
||||
{
|
||||
mix: depsCache: string
|
||||
workdir: string
|
||||
mounts: depsCache: {
|
||||
contents: engine.#CacheDir & {
|
||||
id: "\(mix.app)_deps"
|
||||
concurrency: mix.depsCache
|
||||
}
|
||||
dest: "\(workdir)/deps"
|
||||
}
|
||||
} | {}
|
||||
{
|
||||
mix: buildCache: string
|
||||
workdir: string
|
||||
mounts: buildCache: {
|
||||
contents: engine.#CacheDir & {
|
||||
id: "\(mix.app)_deps"
|
||||
concurrency: mix.buildCache
|
||||
}
|
||||
dest: "\(workdir)/deps"
|
||||
}
|
||||
} | {}
|
||||
}
|
Reference in New Issue
Block a user