update action to dagger 0.2

- Remove AGE key setup
- Update README to use `dagger do`
- Update tests to dagger 0.2

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi 2022-03-09 12:07:13 -08:00
parent 64f8bd95de
commit 24d6bfd692
96 changed files with 15028 additions and 70 deletions

View file

@ -0,0 +1,101 @@
package changelog
actions: {
// Reuse in all mix commands
// 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: "private"
// buildCache: "private"
// }
// workdir: _
// // FIXME: remove copy-pasta
// mounts: nodeModules: {
// contents: dagger.#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: "private"
// }
// dest: "\(workdir)/node_modules"
// }
// },
// ]
// }
// dev: {
// compile: mix.#Compile & {
// env: "dev"
// app: "thechangelog"
// base: inputs.params.runtimeImage
// source: inputs.directories.app.contents
// }
// assets: docker.#Build & {
// steps: [
// // 1. Start from dev runtime build
// {
// output: build.output
// },
// // 2. Build web assets
// mix.#Run & {
// mix: {
// env: "dev"
// app: _appName
// depsCache: "private"
// buildCache: "private"
// }
// // FIXME: move this to a reusable def (yarn package? or private?)
// mounts: nodeModules: {
// contents: dagger.#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.runtimeImage
// source: inputs.directories.app.contents
// }
// // Run tests
// run: docker.#Run & {
// image: build.output
// script: "mix test"
// }
// 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
// }
// }
// }
}

View file

@ -0,0 +1,87 @@
package mix
import (
"dagger.io/dagger"
"universe.dagger.io/docker"
)
#Get: #Run & {
// Applies to all environments
env: null
cache: {
build: null
deps: "locked"
}
container: command: {
name: "sh"
flags: "-c": "mix do deps.get"
}
}
// Compile Elixir dependencies, including the app
#Compile: #Run & {
cache: {
build: "locked"
deps: "locked"
}
container: command: {
name: "sh"
flags: "-c": "mix do deps.compile, compile"
}
}
// Run mix task with all necessary mounts so compiled artefacts get cached
// FIXME: add default image to hexpm/elixir:1.13.2-erlang-23.3.4.11-debian-bullseye-20210902
#Run: {
app: {
// Application name
name: string
// Application source code
source: dagger.#FS
}
// Mix environment
env: string | null
// Configure mix caching
// FIXME: simpler interface, eg. "ro" | "rw"
cache: {
// Dependencies cache
deps: null | "locked"
// Build cache
build: null | "locked"
}
// Run mix in a docker container
container: docker.#Run & {
if env != null {
"env": MIX_ENV: env
}
workdir: mounts.app.dest
mounts: "app": {
contents: app.source
dest: "/mix/app"
}
if cache.deps != null {
mounts: deps: {
contents: dagger.#CacheDir & {
id: "\(app.name)_deps"
concurrency: cache.deps
}
dest: "\(mounts.app.dest)/deps"
}
}
if cache.build != null {
mounts: buildCache: {
contents: dagger.#CacheDir & {
id: "\(app.name)_build_\(env)"
concurrency: cache.build
}
dest: "\(mounts.app.dest)/_build/\(env)"
}
}
}
}

View file

@ -0,0 +1,9 @@
package changelog
import (
"dagger.io/dagger"
)
dagger.#Plan & {
inputs: directories: app: path: "/Users/gerhard/github.com/thechangelog/changelog.com/"
}

View file

@ -0,0 +1,83 @@
package changelog
import (
"dagger.io/dagger"
"universe.dagger.io/docker"
"universe.dagger.io/git"
"universe.dagger.io/examples/changelog.com/elixir/mix"
)
dagger.#Plan & {
// Receive things from client
inputs: {
directories: {
// App source code
app?: _
}
secrets: {
// Docker ID password
docker: _
}
params: {
app: {
// App name
name: string | *"changelog"
// Address of app base image
image: docker.#Ref | *"thechangelog/runtime:2021-05-29T10.17.12Z"
}
test: {
// Address of test db image
db: image: docker.#Ref | *"circleci/postgres:12.6"
}
}
}
// Do things
actions: {
app: {
name: inputs.params.app.name
// changelog.com source code
source: dagger.#FS
if inputs.directories.app != _|_ {
source: inputs.directories.app.contents
}
if inputs.directories.app == _|_ {
fetch: git.#Pull & {
remote: "https://github.com/thechangelog/changelog.com"
ref: "master"
}
source: fetch.output
}
// Assemble base image
base: docker.#Pull & {
source: inputs.params.app.image
}
image: base.output
// Download Elixir dependencies
deps: mix.#Get & {
app: {
"name": name
"source": source
}
container: "image": image
}
// Compile dev environment
dev: mix.#Compile & {
env: "dev"
app: {
"name": name
"source": source
}
container: "image": image
}
}
}
}