Finish the first version of the Go on Docker Swarm use case
Left a few TODOs and ideas for next steps. The goal is to get this live, and enable others to iterate on it via separate PRs. Signed-off-by: Gerhard Lazu <gerhard@lazu.co.uk>
This commit is contained in:
parent
f4da5b9a95
commit
3a2f861dd9
@ -5,74 +5,84 @@ displayed_sidebar: europaSidebar
|
|||||||
|
|
||||||
# Go on Docker Swarm
|
# Go on Docker Swarm
|
||||||
|
|
||||||
> TODO: particubes.com screenshot
|
![particubes.com](/img/use-cases/particubes.com.png)
|
||||||
|
|
||||||
[Particubes](https://particubes.com) is a platform dedicated to voxel games, which are games made out of little cubes (like Minecraft).
|
[Particubes](https://particubes.com) is a platform dedicated to voxel games, which are games made out of little cubes, like Minecraft.
|
||||||
The team consists of 10 developers that like to keep things simple.
|
The team consists of 10 developers that like to keep things simple.
|
||||||
|
They write primarily Go & Lua, push to GitHub and use GitHub Actions for automation.
|
||||||
|
The production setup is a multi-node Docker Swarm cluster running on AWS.
|
||||||
|
|
||||||
Particubes chose Dagger because it was the easiest way to integrate with their Docker Swarm production setup.
|
The Particubes team chose Dagger for continuous deployment because it was the easiest way of integrating GitHub with Docker Swarm.
|
||||||
Every commit to the main branch gets deployed straight to [particubes.com](https://particubes.com) with Dagger running in GitHub Actions.
|
Every commit to the main branch goes straight to [docs.particubes.com](https://docs.particubes.com) via a Dagger pipeline that runs in GitHub Actions.
|
||||||
The Dagger Universe made it very easy for to build this pipeline.
|
`universe.dagger.io/docker` made building this pipeline trivial:
|
||||||
`docker.#Build`, `docker.#Push` and `docker.#Command` was all that it took.
|
|
||||||
|
|
||||||
:::danger
|
:::danger
|
||||||
TODO: this config is pre-Europa, the next step is to convert it to Europa.
|
TODO: this config is meta Europa, meaning that it was not tested. Next steps:
|
||||||
|
- implement it in GitHub Actions and ensure that it all works as expected
|
||||||
|
- update this meta config to the final version that we know works
|
||||||
:::
|
:::
|
||||||
|
|
||||||
This is the entire Particubes Dagger plan:
|
|
||||||
|
|
||||||
```cue
|
```cue
|
||||||
package particubes
|
package particubes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"alpha.dagger.io/dagger"
|
"dagger.io/dagger"
|
||||||
"alpha.dagger.io/docker"
|
"universe.dagger.io/docker"
|
||||||
)
|
)
|
||||||
|
|
||||||
repo: dagger.#Input & {dagger.#Artifact}
|
dagger.#Plan & {
|
||||||
|
inputs: {
|
||||||
swarmSSH: {
|
directories: src: path: "./lua-docs"
|
||||||
user: dagger.#Input & {*"ubuntu" | string}
|
secrets: docs: command: {
|
||||||
host: dagger.#Input & {string}
|
name: "sops"
|
||||||
key: dagger.#Input & {dagger.#Secret}
|
args: ["-d", "../../lua-docs/sops_secrets.yaml"]
|
||||||
|
}
|
||||||
|
params: {
|
||||||
|
image: ref: docker.#Ref | *"registry.particubes.com/lua-docs:latest"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
actions: {
|
||||||
docs: {
|
docs: {
|
||||||
containerImageName: dagger.#Input & {string}
|
// TODO: write GITHUB_SHA into a static /github_sha.txt
|
||||||
containerImageTag: dagger.#Input & {*"latest" | string}
|
build: docker.#Dockerfile & {
|
||||||
|
source: inputs.directories.src.contents
|
||||||
// TODO: write the GIT_SHA into a static /git_sha.txt
|
|
||||||
buildContainerImage: docker.#Build & {
|
|
||||||
source: repo
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test: {
|
||||||
// TODO:
|
// TODO:
|
||||||
// - [ ] bootContainer
|
// - run container
|
||||||
// - [ ] checkHttpResponse
|
// - check http response code
|
||||||
// - [ ] stopContainer
|
// - verify /github_sha.txt value matches GITHUB_SHA
|
||||||
|
// - stop container
|
||||||
publishContainerImage: docker.#Push & {
|
|
||||||
"target": "\(containerImageName):\(containerImageTag)"
|
|
||||||
source: buildContainerImage
|
|
||||||
}
|
}
|
||||||
|
|
||||||
deployContainerImage: docker.#Command & {
|
push: docker.#Push {
|
||||||
ssh: swarmSSH
|
dest: inputs.params.image.ref
|
||||||
command: "docker service update --image registry.particubes.com/lua-docs:$IMAGE_REF lua-docs"
|
image: build.output
|
||||||
env: {
|
|
||||||
"IMAGE_REF": publishContainerImage.ref
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: // check that the expected GIT_SHA is running in production
|
docsSecrets: dagger.#DecodeSecret & {
|
||||||
// checkHttpResponse /git_sha.txt
|
input: inputs.secrets.docs.contents
|
||||||
|
format: "yaml"
|
||||||
|
}
|
||||||
|
deploy: {
|
||||||
|
// TODO:
|
||||||
|
// - run this command in the remote Docker Swarm
|
||||||
|
// - secrests are ready in docsSecrets, e.g. docsSecrets.output.swarmKey.contents
|
||||||
|
}
|
||||||
|
|
||||||
|
verifyDeploy: {
|
||||||
|
// TODO:
|
||||||
|
// - check http response code
|
||||||
|
// - verify /github_sha.txt value matches GITHUB_SHA
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
You can find [the original pipeline](https://github.com/voxowl/particubes/blob/b698777465c02462296de37087dd3c341c29df92/lua-docs/docs.cue) in the Particubes GitHub repository.
|
This is the GitHub Actions workflow config that invokes `dagger`, which in turn runs the above pipeline:
|
||||||
|
|
||||||
Anyone on the Particubes team can run this pipeline locally using `dagger up`.
|
|
||||||
It also runs in GitHub Actions on every commit using the following config:
|
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
name: Dagger/docs.particubes.com
|
name: Dagger/docs.particubes.com
|
||||||
@ -89,13 +99,27 @@ jobs:
|
|||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
with:
|
with:
|
||||||
lfs: true
|
lfs: true
|
||||||
|
// TODO: install sops
|
||||||
- name: Dagger
|
- name: Dagger
|
||||||
uses: dagger/dagger-action@v1
|
uses: dagger/dagger-action@v1
|
||||||
with:
|
with:
|
||||||
age-key: ${{ secrets.DAGGER_AGE_KEY }}
|
age-key: ${{ secrets.DAGGER_AGE_KEY }}
|
||||||
args: up -e docs
|
args: up
|
||||||
```
|
```
|
||||||
|
|
||||||
### What comes next for particubes.com?
|
Since this is a Dagger pipeline, anyone on the team can run it locally with a single command:
|
||||||
|
|
||||||
We don't know but we would like find out 😀
|
```console
|
||||||
|
dagger up
|
||||||
|
```
|
||||||
|
|
||||||
|
This is the first step that enabled the Particubes team to have the same CI/CD experience everywhere.
|
||||||
|
|
||||||
|
We don't know what comes next for particubes.com, but we would like find out. Some ideas:
|
||||||
|
- deploy particubes.com with Dagger
|
||||||
|
- manage the Docker Swarm cluster with Dagger
|
||||||
|
- contribute `universe.dagger.io/particubes` package
|
||||||
|
|
||||||
|
:::tip
|
||||||
|
The latest version of this pipeline can be found at [github.com/voxowl/particubes/lua-docs/docs.cue](https://github.com/voxowl/particubes/blob/b698777465c02462296de37087dd3c341c29df92/lua-docs/docs.cue)
|
||||||
|
:::
|
||||||
|
BIN
website/static/img/use-cases/particubes.com.png
Normal file
BIN
website/static/img/use-cases/particubes.com.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 880 KiB |
Reference in New Issue
Block a user