diff --git a/pkg/build/buildkit/build_test.go b/pkg/build/buildkit/build_test.go index 8355d00..7863f4b 100644 --- a/pkg/build/buildkit/build_test.go +++ b/pkg/build/buildkit/build_test.go @@ -509,62 +509,6 @@ ENV MY_ANOTHER_VAR="another var" _, nerr := dc.ImageRemove(context.TODO(), destImage, dockertypes.ImageRemoveOptions{Force: true}) require.NoError(t, nerr) }() - - t.Run("Job build with Dockerfile", func(t *testing.T) { - destImage := baseRegistry(t, "my-job", "") - - dockerfile := `FROM busybox:latest - - RUN --mount=type=secret,id=tsuru-job-envvars,target=/var/run/secrets/envs.sh \ - . /var/run/secrets/envs.sh \ - && echo ${MY_ENV_VAR} > /tmp/envs \ - && echo ${DATABASE_PASSWORD} >> /tmp/envs - - ENV MY_ANOTHER_VAR="another var" - ` - - req := &pb.BuildRequest{ - Kind: pb.BuildKind_BUILD_KIND_APP_BUILD_WITH_CONTAINER_FILE, - Job: &pb.TsuruJob{ - Name: "my-job", - EnvVars: map[string]string{ - "MY_ENV_VAR": "hello world", - "DATABASE_PASSWORD": "aw3some`p4ss!", - }, - }, - DestinationImages: []string{destImage}, - Containerfile: string(dockerfile), - PushOptions: &pb.PushOptions{ - InsecureRegistry: registryHTTP, - }, - } - - jobFiles, err := NewBuildKit(bc, BuildKitOptions{TempDir: t.TempDir()}).Build(context.TODO(), req, os.Stdout) - require.NoError(t, err) - assert.Equal(t, &pb.TsuruConfig{ - ImageConfig: &pb.ContainerImageConfig{ - Cmd: []string{"sh"}, - }, - }, jobFiles) - - dc := newDockerClient(t) - defer dc.Close() - - r, err := dc.ImagePull(context.TODO(), destImage, dockertypes.ImagePullOptions{}) - require.NoError(t, err) - defer r.Close() - - fmt.Println("Pulling container image", destImage) - _, err = io.Copy(os.Stdout, r) - require.NoError(t, err) - - defer func() { - fmt.Printf("Removing container image %s\n", destImage) - _, nerr := dc.ImageRemove(context.TODO(), destImage, dockertypes.ImageRemoveOptions{Force: true}) - require.NoError(t, nerr) - }() - }) - t.Run("should not store the env vars in the container image manifest", func(t *testing.T) { is, _, err := dc.ImageInspectWithRaw(context.TODO(), destImage) require.NoError(t, err) @@ -579,7 +523,6 @@ ENV MY_ANOTHER_VAR="another var" } } }) - t.Run("should be able to see env vars during the build", func(t *testing.T) { containerCreateResp, err := dc.ContainerCreate(context.TODO(), &dockertypescontainer.Config{ Image: destImage, @@ -623,6 +566,60 @@ ENV MY_ANOTHER_VAR="another var" assert.Empty(t, stderr.String()) }) }) + t.Run("Job build with Dockerfile", func(t *testing.T) { + destImage := baseRegistry(t, "my-job", "") + + dockerfile := `FROM busybox:latest + + RUN --mount=type=secret,id=tsuru-job-envvars,target=/var/run/secrets/envs.sh \ + . /var/run/secrets/envs.sh \ + && echo ${MY_ENV_VAR} > /tmp/envs \ + && echo ${DATABASE_PASSWORD} >> /tmp/envs + + ENV MY_ANOTHER_VAR="another var" + ` + + req := &pb.BuildRequest{ + Kind: pb.BuildKind_BUILD_KIND_APP_BUILD_WITH_CONTAINER_FILE, + Job: &pb.TsuruJob{ + Name: "my-job", + EnvVars: map[string]string{ + "MY_ENV_VAR": "hello world", + "DATABASE_PASSWORD": "aw3some`p4ss!", + }, + }, + DestinationImages: []string{destImage}, + Containerfile: string(dockerfile), + PushOptions: &pb.PushOptions{ + InsecureRegistry: registryHTTP, + }, + } + + jobFiles, err := NewBuildKit(bc, BuildKitOptions{TempDir: t.TempDir()}).Build(context.TODO(), req, os.Stdout) + require.NoError(t, err) + assert.Equal(t, &pb.TsuruConfig{ + ImageConfig: &pb.ContainerImageConfig{ + Cmd: []string{"sh"}, + }, + }, jobFiles) + + dc := newDockerClient(t) + defer dc.Close() + + r, err := dc.ImagePull(context.TODO(), destImage, dockertypes.ImagePullOptions{}) + require.NoError(t, err) + defer r.Close() + + fmt.Println("Pulling container image", destImage) + _, err = io.Copy(os.Stdout, r) + require.NoError(t, err) + + defer func() { + fmt.Printf("Removing container image %s\n", destImage) + _, nerr := dc.ImageRemove(context.TODO(), destImage, dockertypes.ImageRemoveOptions{Force: true}) + require.NoError(t, nerr) + }() + }) t.Run("neither Procfile nor tsuru.yaml, should use command from image manifest", func(t *testing.T) { destImage := baseRegistry(t, "my-app", "")