Skip to content

Commit

Permalink
Update docker.#Run definition and tests
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Chauveau <tom.chauveau@epitech.eu>
  • Loading branch information
TomChv committed Jun 12, 2021
1 parent 8a2fc9a commit b8a97fb
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 248 deletions.
32 changes: 20 additions & 12 deletions docs/reference/universe/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ Build a Docker image from source, using included Dockerfile

_No output._

## #Client
## #Command

A container image to run the Docker client
A container image that can run any docker command

### #Client Inputs
### #Command Inputs

_No input._
| Name | Type | Description |
| ------------- |:-------------: |:-------------: |
|*command* | `string` |Command to execute |

### #Client Outputs
### #Command Outputs

_No output._

Expand Down Expand Up @@ -78,13 +80,19 @@ _No output._

### #Run Inputs

| Name | Type | Description |
| ------------- |:-------------: |:-------------: |
|*ssh.host* | `string` |ssh host |
|*ssh.user* | `string` |ssh user |
|*ssh.port* | `*22 \| int` |ssh port |
|*ssh.key* | `dagger.#Secret` |private key |
|*ref* | `string` |Image reference (e.g: nginx:alpine) |
| Name | Type | Description |
| ------------- |:-------------: |:-------------: |
|*ssh.host* | `string` |ssh host |
|*ssh.user* | `string` |ssh user |
|*ssh.port* | `*22 \| int` |ssh port |
|*ssh.key* | `dagger.#Secret` |private key |
|*ref* | `string` |Image reference (e.g: nginx:alpine) |
|*run.ssh.host* | `string` |ssh host |
|*run.ssh.user* | `string` |ssh user |
|*run.ssh.port* | `*22 \| int` |ssh port |
|*run.ssh.key* | `dagger.#Secret` |private key |
|*run.command* | `"""\n # Run detach container\n OPTS=""\n \n if [ ! -z "$CONTAINER_NAME" ]; then\n \tOPTS="$OPTS --name $CONTAINER_NAME"\n fi\n \n docker container run -d $OPTS "$IMAGE_REF"\n """` |Command to execute |
|*run.env.IMAGE_REF* | `string` |- |

### #Run Outputs

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ TestConfig: {

TestSSH: client: docker.#Command & {
command: #"""
docker $CMD
docker version
"""#
ssh: {
host: TestConfig.host
user: TestConfig.user
key: TestConfig.key
keyPassphrase: TestConfig.keyPassphrase
}
env: CMD: "version"
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ inputs:
TestConfig.key:
secret: ENC[AES256_GCM,data:dbIEUHadOTOdPrmMAgyLGMdIY+FuyWZvv4mRyjr+BbLZavl7/fH6abiQFpPY0x3960iqPB+wEM6wG+VPDivHTj1QRVMGPIV8ZGrfeR/mfeDuaKXDttkWgRN8vyHOZ+oKnI22913tvK59gNbJX8fR0wPfqOCEWbzy+bRBh/bVH//CMwCoSU+v2rZwAqOnGyXCyeGbp+wo5xMufv+Dosgb4uhFk1CPQJfKfBJVMf1EJS0e9/P8GS5UUjevR9eeRnCJ7kdHu26b3lwAHhPWv72O/yuOIKItrgMkSuHz2H2BFdgt5xq/h/SfrONMwymg8+oEiuS3n1C8ZBv8I4RE5XF6GX/xWb9dZJLctbi6oBELtvKXhswnB0PWSK1OXMgrJ5yYFeBPpaBptRBxl0AJhOG92K6xM9O0cRxAT+vtz0zvJ7gIQDZtngcTTS+IMN6Kgmx4daW5x14FbRJRGKKqU+PHeUW2XpN70IwkWXZfLs445O9w8teayPUu3KePZJo8eLkVpWJIyVUnrk/5VIREV8EYZzRFUwTtwYSTefGycPfjz2L01xQR0fn55DxJpcLpCLqjGRhWHQE6Wn4j6aXyzbOXHMIYgw+Rx1egjszdKzgCWaA=,iv:CZyN1UCE0nI2/ch5O7kerfYBbCgoJX+dPvh5dRO3cxc=,tag:hwBmnOdC8Na0dwyUCU3QDw==,type:str]
TestConfig.keyPassphrase:
secret: ENC[AES256_GCM,data:LM8qBQ1uZHVA,iv:z4MOKWy9owo69oy8Z4Gmd7fT7uXMR/Sp2qgM38wjWM4=,tag:WwZt3WtlROY3+j2LG8M39w==,type:str]
secret: ENC[AES256_GCM,data:RZK8tx7PZaYtmg==,iv:yFXA8CROxAbrhz/i3PQHeqCFh4rMo+GHITpVxfAOkdo=,tag:Ep1J0nazTcc8EjHP6GbwAQ==,type:str]
TestConfig.user:
text: daggerci
sops:
Expand All @@ -23,8 +23,8 @@ sops:
R2tNU2JJWHFQTmhnUDd6eE13UUhQazgK+OQ50Q3+S5Fn2Y132ZeDrgUKWPcAk+et
q8ppfZiPOtH4p6MwboSuh/vaTAAsxks7ctnqnU1pY+EHfnp8bHYHgQ==
-----END AGE ENCRYPTED FILE-----
lastmodified: "2021-06-10T15:09:45Z"
mac: ENC[AES256_GCM,data:axraLjtO6zs1Zo2UVcrxJqLHlQea1pBcGCwCxIp43vw+L07haNtuqf0lJ5SL9XfB/yGjYtykP+Ld1evbgnUT4nqxRuHkN2NgHshmrytdptnOKCuTqE4sYWRt5Nny2linXmsqAYS9HAw8htw0DOjFUDruIAITjVLb8/sSgvS7wb4=,iv:Ahqguwy+9gmIzUMxDLzf9JuNybst+cMabfDciL5ZeJ4=,tag:EggVqFtbqLjMyHhrmqY1Ug==,type:str]
lastmodified: "2021-06-11T16:09:47Z"
mac: ENC[AES256_GCM,data:RTbDkgxWqVa4kgJPXny9u9hfwF1NG3g9L/6P2P44KE97yNdoxuAkuU1hs6DiATl4hgeck7p56gWLeUTeGAi+llMDqOodmSQEtD/XZvvdmyh4J+09+jg9QRwSL54xNR4Q83YBWy5PZm+hyYQdVl9H3omMCrdO78ydYXPSdDnRk3I=,iv:crEuUK+jQ6QBrf/Dxouu9+I3VXdZazKnHJ1g5JZLD0E=,tag:ymExWezKBTowuH4pugiQ/g==,type:str]
pgp: []
encrypted_suffix: secret
version: 3.7.1
32 changes: 0 additions & 32 deletions stdlib/.dagger/env/docker-run-ssh-passphrase/plan/passphrase.cue

This file was deleted.

30 changes: 0 additions & 30 deletions stdlib/.dagger/env/docker-run-ssh-passphrase/values.yaml

This file was deleted.

This file was deleted.

30 changes: 0 additions & 30 deletions stdlib/.dagger/env/docker-run-ssh-wrong-passphrase/values.yaml

This file was deleted.

104 changes: 10 additions & 94 deletions stdlib/docker/docker.cue
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package docker

import (
"strconv"

"dagger.io/dagger"
"dagger.io/dagger/op"
)
Expand Down Expand Up @@ -78,38 +76,7 @@ import (
secret: dagger.#Secret
} @dagger(input)

#code: #"""
if [ -n "$DOCKER_HOSTNAME" ]; then
export DOCKER_HOST="ssh://$DOCKER_USERNAME@$DOCKER_HOSTNAME:$DOCKER_PORT"
# Start ssh-agent
eval $(ssh-agent) > /dev/null
# Add key
if [ -f "/key" ]; then
message="$(ssh-keygen -y -f /key < /dev/null 2>&1)" || {
>&2 echo "$message"
exit 1
}
ssh-add /key > /dev/null
if [ "$?" != 0 ]; then
exit 1
fi
fi
if [[ ! -z $FINGERPRINT ]]; then
mkdir -p "$HOME"/.ssh
# Add user's fingerprint to known hosts
echo "$FINGERPRINT" >> "$HOME"/.ssh/known_hosts
else
# Add host to known hosts
ssh -i /key -o "UserKnownHostsFile "$HOME"/.ssh/known_hosts" -o "StrictHostKeyChecking accept-new" -p "$DOCKER_PORT" "$DOCKER_USERNAME"@"$DOCKER_HOSTNAME" /bin/true > /dev/null 2>&1
fi
fi
#command: #"""
# Run detach container
OPTS=""
Expand All @@ -120,67 +87,16 @@ import (
docker container run -d $OPTS "$IMAGE_REF"
"""#

#up: [
op.#Load & {from: #Client},

if registry != _|_ {
op.#DockerLogin & {registry}
},

if ssh.keyPassphrase != _|_ {
op.#WriteFile & {
content: #"""
#!/bin/bash
cat /passphrase
"""#
dest: "/get_passphrase"
mode: 0o500
run: #Command & {
"ssh": ssh
command: #command
env: {
IMAGE_REF: ref
if name != _|_ {
CONTAINER_NAME: name
}
},

op.#WriteFile & {
content: #code
dest: "/entrypoint.sh"
},

op.#Exec & {
always: true
args: [
"/bin/sh",
"--noprofile",
"--norc",
"-eo",
"pipefail",
"/entrypoint.sh",
]
env: {
IMAGE_REF: ref
if ssh != _|_ {
DOCKER_HOSTNAME: ssh.host
DOCKER_USERNAME: ssh.user
DOCKER_PORT: strconv.FormatInt(ssh.port, 10)
if ssh.keyPassphrase != _|_ {
SSH_ASKPASS: "/get_passphrase"
DISPLAY: "1"
}
if ssh.fingerprint != _|_ {
FINGERPRINT: ssh.fingerprint
}
}
if name != _|_ {
CONTAINER_NAME: name
}
}
mount: {
if ssh.key != _|_ {
"/key": secret: ssh.key
}
if ssh.keyPassphrase != _|_ {
"/passphrase": secret: ssh.keyPassphrase
}
}
},
]
}
}
}

// Build a Docker image from the provided Dockerfile contents
Expand Down
17 changes: 4 additions & 13 deletions stdlib/universe.bats
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,22 @@ setup() {
}

@test "docker command: ssh" {
dagger -e docker-command-ssh up
dagger -e docker-command-ssh up
}

@test "docker command: ssh with key passphrase" {
dagger -e docker-command-ssh-key-passphrase up
dagger -e docker-command-ssh-key-passphrase up
}

@test "docker command: ssh with wrong key passphrase" {
run dagger -e docker-command-ssh-wrong-key-passphrase up
assert_failure
run dagger -e docker-command-ssh-wrong-key-passphrase up
assert_failure
}

@test "docker run: ssh" {
dagger -e docker-run-ssh up
}

@test "docker run: ssh with passphrase" {
dagger -e docker-run-ssh-passphrase up
}

@test "docker run: ssh with wrong passphrase" {
run dagger -e docker-run-ssh-wrong-passphrase up
assert_failure
}

@test "google cloud: gcr" {
dagger -e google-gcr up
}
Expand Down

0 comments on commit b8a97fb

Please sign in to comment.