Merge pull request #1003 from samalba/docker-run-local

Docker run local
This commit is contained in:
Sam Alba 2021-09-23 15:28:26 -07:00 committed by GitHub
commit 9120c52545
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 47 additions and 24 deletions

View File

@ -78,15 +78,7 @@ Push a docker image to a remote registry
| Name | Type | Description | | 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) | |*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.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.env.IMAGE_REF* | `string` |- |
|*run.registries* | `[]` |Image registries | |*run.registries* | `[]` |Image registries |

View File

@ -1,6 +1,10 @@
plan: plan:
package: ./docker/tests/run-local package: ./docker/tests/run-local
name: docker-run-local name: docker-run-local
inputs:
dockersocket:
socket:
unix: /var/run/docker.sock
sops: sops:
kms: [] kms: []
gcp_kms: [] gcp_kms: []
@ -16,8 +20,8 @@ sops:
cnh2eHU5TzFjVkNvTzUyczFBL0pwTDQK60+wrLmTaD3Ws5ZAXdqBkMjaVP7Iz69k cnh2eHU5TzFjVkNvTzUyczFBL0pwTDQK60+wrLmTaD3Ws5ZAXdqBkMjaVP7Iz69k
UrkqkMbaUlvvSKK7dB5MuTGEEN6A1viAGal9ZjDHlSobkNPuE24QEA== UrkqkMbaUlvvSKK7dB5MuTGEEN6A1viAGal9ZjDHlSobkNPuE24QEA==
-----END AGE ENCRYPTED FILE----- -----END AGE ENCRYPTED FILE-----
lastmodified: "2021-07-08T09:54:17Z" lastmodified: "2021-09-21T23:13:41Z"
mac: ENC[AES256_GCM,data:Fwvi/c8oNOtB8yUl9R0teUibQQLfTyPjhua2DiNhcAZYT1IJeUXnLl+llAGl8hOl5pR1ZLIgbpW46HW6ZBn3bZND0K5/uZL3CNM5+MLlrHzIxy1xFbXXDLYHH0rbRfGmQtSu2b/JKwTiTfbiPSd6VASFtIvoeTU79hQXE2DVmWk=,iv:iFVZvw4KMLOo/u1IrHMF2xZlER2Oqn2RY6pM78o+FyI=,tag:nXJnewaOGz/URq8o8+uYFg==,type:str] mac: ENC[AES256_GCM,data:jF/Uu0y+uXym4UeXfRmzuZvEkqbk12vzByoiMOk2X/lQ+26x5LzWWwso7/2KjAnDonrKaPLChpaBJE89SIyuLKcU43/ttQ3xZK8TBfj7RWU5hT0Bj1kW2w258LLqcvYSrmHsvzh7aigG561LowJYysoHt4Bt6m66mwZq7wjelqA=,iv:toaSdz6F1oNf5ELSP3/aHLEAzyEAXKLZfxJBoR/aBOY=,tag:2xnNbmSsGTsMD0YT1+valA==,type:str]
pgp: [] pgp: []
encrypted_suffix: secret encrypted_suffix: secret
version: 3.7.1 version: 3.7.1

View File

@ -57,6 +57,9 @@ import (
[string]: true @dagger(input) [string]: true @dagger(input)
} }
// Mount docker socket
socket?: dagger.#Stream @dagger(input)
// Additional packages to install // Additional packages to install
package: { package: {
[string]: true | false | string @dagger(input) [string]: true | false | string @dagger(input)
@ -213,6 +216,9 @@ import (
"/keyPassphrase": secret: ssh.keyPassphrase "/keyPassphrase": secret: ssh.keyPassphrase
} }
} }
if socket != _|_ {
"/var/run/docker.sock": stream: socket
}
for dest, o in mount { for dest, o in mount {
"\(dest)": o "\(dest)": o
} }

View File

@ -28,6 +28,9 @@ import (
keyPassphrase?: dagger.#Secret @dagger(input) keyPassphrase?: dagger.#Secret @dagger(input)
} }
// Mount local docker socket
socket?: dagger.#Stream & dagger.#Input
// Accept either a contaxt, a docker-compose or both together // Accept either a contaxt, a docker-compose or both together
source?: dagger.#Artifact @dagger(input) source?: dagger.#Artifact @dagger(input)
composeFile?: string @dagger(input) composeFile?: string @dagger(input)
@ -65,7 +68,13 @@ import (
"""# """#
run: docker.#Command & { run: docker.#Command & {
if ssh != _|_ {
"ssh": ssh "ssh": ssh
}
if socket != _|_ {
"socket": socket
}
command: #code command: #code
package: "docker-compose": true package: "docker-compose": true
"registries": registries "registries": registries

View File

@ -102,7 +102,7 @@ import (
#Run: { #Run: {
// Connect to a remote SSH server // Connect to a remote SSH server
ssh: { ssh?: {
// ssh host // ssh host
host: dagger.#Input & {string} host: dagger.#Input & {string}
@ -122,6 +122,9 @@ import (
keyPassphrase?: dagger.#Input & {dagger.#Secret} keyPassphrase?: dagger.#Input & {dagger.#Secret}
} }
// Mount local docker socket
socket?: dagger.#Stream & dagger.#Input
// Image reference (e.g: nginx:alpine) // Image reference (e.g: nginx:alpine)
ref: dagger.#Input & {string} ref: dagger.#Input & {string}
@ -147,7 +150,13 @@ import (
"""# """#
run: #Command & { run: #Command & {
if ssh != _|_ {
"ssh": ssh "ssh": ssh
}
if socket != _|_ {
"socket": socket
}
command: #command command: #command
env: { env: {
IMAGE_REF: ref IMAGE_REF: ref

View File

@ -1,9 +1,12 @@
package docker package docker
import ( import (
"alpha.dagger.io/dagger"
"alpha.dagger.io/random" "alpha.dagger.io/random"
) )
dockersocket: dagger.#Stream & dagger.#Input
suffix: random.#String & { suffix: random.#String & {
seed: "" seed: ""
} }
@ -11,4 +14,5 @@ suffix: random.#String & {
run: #Run & { run: #Run & {
name: "daggerci-test-local-\(suffix.out)" name: "daggerci-test-local-\(suffix.out)"
ref: "hello-world" ref: "hello-world"
socket: dockersocket
} }

View File

@ -76,8 +76,7 @@ setup() {
} }
@test "docker run: local" { @test "docker run: local" {
skip "Not implemented yet + missing inputs leading to failure" dagger -e docker-run-local up
# dagger -e docker-run-local up
} }
@test "docker build" { @test "docker build" {