Merge pull request #1525 from TomChv/feat/docker-dockerfile

Implement docker.#Dockerfile
This commit is contained in:
Gerhard Lazu 2022-03-18 13:41:30 +00:00 committed by GitHub
commit 749278965c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 141 additions and 10 deletions

View File

@ -0,0 +1,5 @@
# generated by dagger
dagger.lock
alpha.dagger.io
dagger.io
universe.dagger.io

View File

@ -61,18 +61,43 @@ import (
// Build step that executes a Dockerfile
#Dockerfile: {
// Source directory
source: dagger.#FS
// FIXME: not yet implemented
*{
// Look for Dockerfile in source at default path
path: "Dockerfile"
// Dockerfile definition or path into source
dockerfile: *{
path: string | *"Dockerfile"
} | {
// Look for Dockerfile in source at a custom path
path: string
} | {
// Custom dockerfile contents
contents: string
}
// Registry authentication
// Key must be registry address
auth: [registry=string]: {
username: string
secret: dagger.#Secret
}
platforms: [...string]
target?: string
buildArg: [string]: string
label: [string]: string
hosts: [string]: string
_build: dagger.#Dockerfile & {
"source": source
"auth": auth
"dockerfile": dockerfile
"platforms": platforms
if target != _|_ {
"target": target
}
"buildArg": buildArg
"label": label
"hosts": hosts
}
output: #Image & {
rootfs: _build.output
config: _build.config
}
}

View File

@ -0,0 +1,69 @@
package docker
import (
"dagger.io/dagger"
"universe.dagger.io/docker"
)
dagger.#Plan & {
client: filesystem: "./testdata": read: contents: dagger.#FS
actions: test: dockerfile: {
simple: {
build: docker.#Build & {
steps: [
docker.#Dockerfile & {
source: dagger.#Scratch
dockerfile: contents: """
FROM alpine:3.15
RUN echo -n hello world >> /test.txt
"""
},
docker.#Run & {
command: {
name: "/bin/sh"
args: ["-c", """
# Verify that docker.#Dockerfile correctly connect output
# into other steps
grep -q "hello world" /test.txt
"""]
}
},
]
}
verify: dagger.#ReadFile & {
input: build.output.rootfs
path: "/test.txt"
} & {
contents: "hello world"
}
}
withInput: {
build: docker.#Build & {
steps: [
docker.#Dockerfile & {
source: client.filesystem."./testdata".read.contents
},
docker.#Run & {
command: {
name: "/bin/sh"
args: ["-c", """
hello >> /test.txt
"""]
}
},
]
}
verify: dagger.#ReadFile & {
input: build.output.rootfs
path: "/test.txt"
} & {
contents: "hello world"
}
}
}
}

View File

@ -5,5 +5,8 @@ setup() {
}
@test "docker" {
dagger "do" -p ./ test
dagger "do" -p ./build.cue test
dagger "do" -p ./dockerfile.cue test
dagger "do" -p ./run.cue test
dagger "do" -p ./image.cue test
}

View File

@ -0,0 +1,19 @@
###
# STAGE: builder
# Build a simple go program
# GO TO STAGE: app
###
FROM golang:1.17-alpine as builder
WORKDIR /app
COPY go.mod .
COPY main.go .
RUN go build -o hello main.go
FROM alpine:3.15@sha256:21a3deaa0d32a8057914f36584b5288d2e5ecc984380bc0118285c70fa8c9300
COPY --from=builder /app/hello /bin/hello
ENTRYPOINT ["hello"]

View File

@ -0,0 +1,3 @@
module test.com
go 1.17

View File

@ -0,0 +1,7 @@
package main
import "fmt"
func main() {
fmt.Printf("hello world")
}