Add tests on docker.#Dockerfile

Signed-off-by: Vasek - Tom C <tom.chauveau@epitech.eu>
This commit is contained in:
Vasek - Tom C 2022-01-28 14:53:06 +01:00
parent 562678779e
commit c90be8423e
No known key found for this signature in database
GPG Key ID: 175D82E572427960
5 changed files with 100 additions and 0 deletions

View File

@ -0,0 +1,34 @@
package test
import (
"dagger.io/dagger"
"dagger.io/dagger/engine"
"universe.dagger.io/docker"
)
dagger.#Plan & {
inputs: directories: testdata: path: "./testdata"
actions: {
image: docker.#Build & {
steps: [
docker.#Dockerfile & {
input: rootfs: inputs.directories.testdata.contents
},
docker.#Run & {
always: true
script: """
hello >> /test.txt
"""
},
]
}
verify: engine.#ReadFile & {
input: image.output.rootfs
path: "/test.txt"
} & {
contents: "hello world"
}
}
}

View File

@ -0,0 +1,37 @@
package test
import (
"dagger.io/dagger"
"dagger.io/dagger/engine"
"universe.dagger.io/docker"
)
dagger.#Plan & {
actions: {
build: docker.#Build & {
steps: [
docker.#Dockerfile & {
dockerfile: contents: """
FROM alpine:3.15
RUN echo -n hello world >> /test.txt
"""
},
docker.#Run & {
script: """
# Verify that docker.#Dockerfile correctly connect output
# into other steps
grep -q "hello world" /test.txt
"""
},
]
}
verify: engine.#ReadFile & {
input: build.output.rootfs
path: "/test.txt"
} & {
contents: "hello world"
}
}
}

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")
}