Skip to content

chore: make sure directives are correct #235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions envbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,12 @@ func Run(ctx context.Context, options Options) error {
}
}

// Make sure the Dockerfile is using the correct directives to run envbuilder
buildParams.DockerfileContent = buildParams.DockerfileContent + "\n" +
"USER root \n" +
"WORKDIR / \n" +
"ENTRYPOINT [\"/.envbuilder/bin/envbuilder\"]"

HijackLogrus(func(entry *logrus.Entry) {
for _, line := range strings.Split(entry.Message, "\r") {
options.Logger(notcodersdk.LogLevelInfo, "#%d: %s", stageNumber, color.HiBlackString(line))
Expand Down
42 changes: 42 additions & 0 deletions integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1354,6 +1354,48 @@ COPY --from=a /root/date.txt /date.txt`, testImageAlpine, testImageAlpine),
})
}

func TestDirectives(t *testing.T) {
t.Parallel()

srv := createGitServer(t, gitServerOptions{
files: map[string]string{
".devcontainer/entrypoint.sh": "#!/bin/sh\necho 'Hello, world!'",
".devcontainer/Dockerfile": "FROM " + testImageAlpine + "\n" +
"RUN addgroup -S coder && adduser -S coder -G coder \n" +
"USER coder\n" +
"WORKDIR /app\n" +
"ENTRYPOINT [\"./entrypoint.sh\"]",
".devcontainer/devcontainer.json": `{
"name": "Test",
"build": {
"dockerfile": "Dockerfile"
},
}`,
},
})

testReg := setupInMemoryRegistry(t, setupInMemoryRegistryOpts{})
testRepo := testReg + "/test"
ref, err := name.ParseReference(testRepo + ":latest")
require.NoError(t, err)

_, err = runEnvbuilder(t, options{env: []string{
envbuilderEnv("GIT_URL", srv.URL),
envbuilderEnv("CACHE_REPO", testRepo),
envbuilderEnv("PUSH_IMAGE", "1"),
}})
require.NoError(t, err)

image, err := remote.Image(ref)
require.NoError(t, err, "expected image to be present after build + push")
configFile, err := image.ConfigFile()
require.NoError(t, err, "expected image to return a config file")

require.Equal(t, configFile.Config.User, "root", "value does not match any of the possible root user values.")
require.Equal(t, configFile.Config.WorkingDir, "/", "expected image to have root working directory")
require.Equal(t, configFile.Config.Entrypoint, []string{"/.envbuilder/bin/envbuilder"}, "expected image to have envbuilder entrypoint")
Comment on lines +1395 to +1397
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably a good idea to assert the opposite in some other test when we don't push

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If they are not pushed, what reference can we use to get the local image and inspect it?

}

type setupInMemoryRegistryOpts struct {
Username string
Password string
Expand Down
Loading