-
Notifications
You must be signed in to change notification settings - Fork 45
chore(integration): test with a locally-hosted devcontainer feature #438
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1545,6 +1545,23 @@ COPY %s .`, testImageAlpine, inclFile) | |
func TestPushImage(t *testing.T) { | ||
t.Parallel() | ||
|
||
// Write a test feature to an in-memory registry. | ||
testFeature := registrytest.WriteContainer(t, registrytest.New(t), "features/test-feature:latest", features.TarLayerMediaType, map[string]any{ | ||
"install.sh": `#!/bin/sh | ||
echo "${MESSAGE}" > /root/message.txt`, | ||
"devcontainer-feature.json": features.Spec{ | ||
ID: "test-feature", | ||
Name: "test feature", | ||
Version: "v0.0.1", | ||
Options: map[string]features.Option{ | ||
"message": { | ||
Type: "string", | ||
Default: "hello world", | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
t.Run("CacheWithoutPush", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
|
@@ -1557,12 +1574,15 @@ WORKDIR $WORKDIR | |
ENV FOO=bar | ||
RUN echo $FOO > /root/foo.txt | ||
RUN date --utc > /root/date.txt`, testImageAlpine), | ||
".devcontainer/devcontainer.json": `{ | ||
".devcontainer/devcontainer.json": fmt.Sprintf(`{ | ||
"name": "Test", | ||
"build": { | ||
"dockerfile": "Dockerfile" | ||
}, | ||
}`, | ||
"features": { | ||
%q: {} | ||
} | ||
}`, testFeature), | ||
}, | ||
}) | ||
|
||
|
@@ -1603,7 +1623,7 @@ RUN date --utc > /root/date.txt`, testImageAlpine), | |
envbuilderEnv("CACHE_REPO", testRepo), | ||
envbuilderEnv("GET_CACHED_IMAGE", "1"), | ||
}}) | ||
require.ErrorContains(t, err, "uncached COPY command is not supported in cache probe mode") | ||
require.Regexp(t, `uncached.*?command.*?is not supported in cache probe mode`, err.Error()) | ||
}) | ||
|
||
t.Run("CacheAndPush", func(t *testing.T) { | ||
|
@@ -1612,21 +1632,27 @@ RUN date --utc > /root/date.txt`, testImageAlpine), | |
ctx, cancel := context.WithCancel(context.Background()) | ||
t.Cleanup(cancel) | ||
|
||
// Given: a git repository with a devcontainer.json that references the | ||
// feature | ||
srv := gittest.CreateGitServer(t, gittest.Options{ | ||
Files: map[string]string{ | ||
".devcontainer/Dockerfile": fmt.Sprintf(`FROM %s | ||
USER root | ||
ARG WORKDIR=/ | ||
WORKDIR $WORKDIR | ||
ENV FOO=bar | ||
RUN echo $FOO > /root/foo.txt | ||
RUN date --utc > /root/date.txt`, testImageAlpine), | ||
".devcontainer/devcontainer.json": `{ | ||
"name": "Test", | ||
"build": { | ||
"dockerfile": "Dockerfile" | ||
}, | ||
}`, | ||
USER root | ||
ARG WORKDIR=/ | ||
WORKDIR $WORKDIR | ||
ENV FOO=bar | ||
RUN echo $FOO > /root/foo.txt | ||
RUN date --utc > /root/date.txt`, testImageAlpine), | ||
".devcontainer/devcontainer.json": fmt.Sprintf(` | ||
{ | ||
"name": "Test", | ||
"build": { | ||
"dockerfile": "Dockerfile" | ||
}, | ||
"features": { | ||
%q: {} | ||
} | ||
}`, testFeature), | ||
}, | ||
}) | ||
|
||
|
@@ -1671,6 +1697,9 @@ RUN date --utc > /root/date.txt`, testImageAlpine), | |
require.Regexp(t, `(?s)^USAGE:\s+envbuilder`, strings.TrimSpace(out)) | ||
out = execContainer(t, ctr.ID, "cat /root/date.txt") | ||
require.NotEmpty(t, strings.TrimSpace(out)) | ||
// Then: the feature install script was run | ||
out = execContainer(t, ctr.ID, "cat /root/message.txt") | ||
require.Equal(t, "hello world", strings.TrimSpace(out)) | ||
}) | ||
|
||
t.Run("CacheAndPushDevcontainerOnly", func(t *testing.T) { | ||
|
@@ -1702,7 +1731,7 @@ RUN date --utc > /root/date.txt`, testImageAlpine), | |
_, err = runEnvbuilder(t, runOpts{env: append(opts, | ||
envbuilderEnv("GET_CACHED_IMAGE", "1"), | ||
)}) | ||
require.ErrorContains(t, err, "error probing build cache: uncached COPY command") | ||
require.Regexp(t, "error probing build cache: uncached.*?command.*?is not supported in cache probe mode", err.Error()) | ||
johnstcn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Then: it should fail to build the image and nothing should be pushed | ||
_, err = remote.Image(ref) | ||
require.ErrorContains(t, err, "NAME_UNKNOWN", "expected image to not be present before build + push") | ||
|
@@ -2293,26 +2322,23 @@ RUN date --utc > /root/date.txt`, testImageAlpine), | |
require.NoError(t, err) | ||
}) | ||
|
||
t.Run("CacheAndPushDevcontainerFeatures", func(t *testing.T) { | ||
t.Run("CacheAndPushDevcontainerFeaturesOverrideOption", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
t.Cleanup(cancel) | ||
|
||
srv := gittest.CreateGitServer(t, gittest.Options{ | ||
Files: map[string]string{ | ||
// NOTE(mafredri): We can't cache the feature in our local | ||
// registry because the image media type is incompatible. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for figuring this out! ❤️ |
||
".devcontainer/devcontainer.json": fmt.Sprintf(` | ||
{ | ||
"image": %q, | ||
"features": { | ||
"ghcr.io/devcontainers/feature-starter/color:1": { | ||
"favorite": "green" | ||
} | ||
} | ||
} | ||
`, testImageUbuntu), | ||
{ | ||
"image": %q, | ||
"features": { | ||
%q: { | ||
"message": "my favorite color is green" | ||
} | ||
} | ||
}`, testImageUbuntu, testFeature), | ||
}, | ||
}) | ||
|
||
|
@@ -2343,7 +2369,7 @@ RUN date --utc > /root/date.txt`, testImageAlpine), | |
ctr := startContainerFromRef(ctx, t, cli, cachedRef) | ||
|
||
// Check that the feature is present in the image. | ||
out := execContainer(t, ctr.ID, "/usr/local/bin/color") | ||
out := execContainer(t, ctr.ID, "cat /root/message.txt") | ||
require.Contains(t, strings.TrimSpace(out), "my favorite color is green") | ||
}) | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.