162 lines
3.2 KiB
Markdown
162 lines
3.2 KiB
Markdown
# Deployment API
|
|
|
|
```
|
|
.
|
|
|-- Makefile
|
|
|-- README.md
|
|
|-- docker-compose.yml
|
|
`-- src
|
|
|-- deploymentagent # Code and tests for the deployment agent
|
|
`-- podman # Podman inside of Docker replicating behavior on the live server for local testing
|
|
```
|
|
|
|
Accepts a deployment specification to produce a deployment state file.
|
|
|
|
## Setup
|
|
|
|
This project makes use of `gitlab.com/infektcommon/settings`, in order to be able to build it locally with Docker, you will need to provide the *path* to an ssh private key with access to Gitlab in the `Makefile`, like so:
|
|
|
|
```Makefile
|
|
$ cat Makefile
|
|
IMAGE=deploymentagent
|
|
VERSION=latest
|
|
KEY_NAME=/home/user/.ssh/my-key
|
|
```
|
|
|
|
## Testing
|
|
### Launch the testing environment
|
|
```sh
|
|
make build
|
|
make run
|
|
```
|
|
### Launch unit tests in a separate shell
|
|
```sh
|
|
make test
|
|
```
|
|
### Cleanup after you are done
|
|
Removes dangling containers and volumes
|
|
```sh
|
|
make clean
|
|
```
|
|
|
|
## Data formats
|
|
|
|
### Deployment specification
|
|
|
|
```json
|
|
[
|
|
{
|
|
"app" : "foo",
|
|
"version" : "latest"
|
|
},
|
|
{
|
|
"app" : "bar",
|
|
"version" : "latest"
|
|
}
|
|
]
|
|
```
|
|
If the same app is specified multiple times, the last entry in the list takes precedence.
|
|
|
|
### Deployment state
|
|
|
|
```json
|
|
{
|
|
"foo": "latest",
|
|
"bar": "latest",
|
|
}
|
|
```
|
|
The deployment state file is intended to be read by Nix, which will produce a systemd unit file that configures the Podman container.
|
|
|
|
## Commands
|
|
|
|
```sh
|
|
curl -u'testuser:testpass' -i -XPOST localhost:8080/deploy -d '[{"app":"alpine", "version": "3.12"}]'
|
|
{"Message": "Queued for deployment", "DeploymentId": "1609855921147639"}
|
|
```
|
|
|
|
```sh
|
|
curl -u'testuser:testpass' -XGET localhost:8080/status | json_pp
|
|
```
|
|
```json
|
|
[
|
|
{
|
|
"Id": 1609855921147639,
|
|
"Status": "queued",
|
|
"StatusMessage": "Queued for deployment",
|
|
"DeploymentSpec": [
|
|
{
|
|
"app": "alpine",
|
|
"version": "3.12"
|
|
}
|
|
],
|
|
"DeploymentState": null
|
|
}
|
|
]
|
|
```
|
|
.. deployment in progress ..
|
|
```sh
|
|
curl -u'testuser:testpass' -XGET localhost:8080/status | json_pp
|
|
```
|
|
```json
|
|
[
|
|
{
|
|
"Id": 1610356267147639,
|
|
"Status": "deployed",
|
|
"StatusMessage": "Deployment successful",
|
|
"DeploymentSpec": [
|
|
{
|
|
"app": "alpine",
|
|
"version": "3.12"
|
|
}
|
|
],
|
|
"DeploymentState": {
|
|
"alpine": "3.12"
|
|
}
|
|
}
|
|
]
|
|
```
|
|
|
|
```sh
|
|
curl -u'testuser:testpass' -i -XPOST localhost:8080/deploy -d '[{"app":"alpine", "version": "latest"}, {"app":"busybox", "version": "latest"}]'
|
|
```
|
|
|
|
```json
|
|
[
|
|
{
|
|
"Id": 1610356267147639,
|
|
"Status": "deployed",
|
|
"StatusMessage": "Deployment successful",
|
|
"DeploymentSpec": [
|
|
{
|
|
"app": "alpine",
|
|
"version": "3.12"
|
|
}
|
|
],
|
|
"DeploymentState": {
|
|
"alpine": "3.12"
|
|
}
|
|
},
|
|
{
|
|
"Id": 1610356267266631,
|
|
"Status": "deployed",
|
|
"StatusMessage": "Deployment successful",
|
|
"DeploymentSpec": [
|
|
{
|
|
"app": "alpine",
|
|
"version": "latest"
|
|
},
|
|
{
|
|
"app": "alpine",
|
|
"version": "latest"
|
|
}
|
|
],
|
|
"DeploymentState": {
|
|
"alpine": "latest",
|
|
"busybox": "latest"
|
|
}
|
|
}
|
|
]
|
|
```
|
|
|
|
To test with `api`, `web`, `filestore`, `html2pdf`, the Podman container would need to be authenticated with the Gitlab registry of the glv5 project.
|