Skip to content
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

devcontainer.json improvements #205

Merged
merged 6 commits into from
Feb 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions dev/build
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
shell
--pull
--no-interactive
--volume ${XDG_CACHE_HOME}/maven:/root/.m2:z
docker.io/metio/devcontainers-graalvm:latest
Expand Down
1 change: 1 addition & 0 deletions dev/env
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
shell
--pull
--volume ${XDG_CACHE_HOME}/maven:/root/.m2:z
docker.io/metio/devcontainers-graalvm:latest
bash
1 change: 1 addition & 0 deletions dev/native
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
shell
--pull
--no-interactive
--volume ${XDG_CACHE_HOME}/maven:/root/.m2:z
docker.io/metio/devcontainers-graalvm:latest
Expand Down
1 change: 1 addition & 0 deletions dev/serve
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
shell
--pull
--no-interactive
--publish=1313:1313
docker.io/klakegg/hugo:latest
Expand Down
1 change: 1 addition & 0 deletions dev/website
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
shell
--pull
--no-interactive
docker.io/klakegg/hugo:latest
--minify --printI18nWarnings --printPathWarnings --printUnusedTemplates --source docs
69 changes: 33 additions & 36 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>wtf.metio.maven.parents</groupId>
<artifactId>maven-parents-java-stable</artifactId>
<version>2023.1.27</version>
<version>2023.2.17</version>
</parent>

<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
Expand Down Expand Up @@ -211,16 +211,13 @@
<goal>compile-no-fork</goal>
</goals>
<phase>package</phase>
<configuration>
<imageName>ilo</imageName>
<mainClass>${ilo.mainClass}</mainClass>
<skipNativeBuild>${skipNativeBuild}</skipNativeBuild>
</configuration>
</execution>
</executions>
<configuration>
<imageName>ilo</imageName>
<mainClass>${ilo.mainClass}</mainClass>
<buildArgs>
<buildArg>--no-fallback</buildArg>
</buildArgs>
<skipNativeBuild>${skipNativeBuild}</skipNativeBuild>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
Expand Down Expand Up @@ -342,33 +339,33 @@
<sourceDirectory>${project.build.directory}/generated-picocli-docs</sourceDirectory>
</configuration>
</plugin>
<plugin>
<!-- See http://ec4j.github.io/editorconfig-maven-plugin/ for full configuration reference -->
<groupId>org.ec4j.maven</groupId>
<artifactId>editorconfig-maven-plugin</artifactId>
<executions>
<execution>
<id>check</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<excludes>
<!-- lots of false-positives? TODO: investigate and fix -->
<exclude>docs/**/*</exclude>
<!-- exclude for GitHub Actions -->
<exclude>signing.key.asc</exclude>
</excludes>
<includes>
<include>pom.xml</include>
<include>maven-version-rules.xml</include>
<include>src/**/*</include>
</includes>
</configuration>
</plugin>
<!-- <plugin>-->
<!-- &lt;!&ndash; See http://ec4j.github.io/editorconfig-maven-plugin/ for full configuration reference &ndash;&gt;-->
<!-- <groupId>org.ec4j.maven</groupId>-->
<!-- <artifactId>editorconfig-maven-plugin</artifactId>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <id>check</id>-->
<!-- <phase>verify</phase>-->
<!-- <goals>-->
<!-- <goal>check</goal>-->
<!-- </goals>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- <configuration>-->
<!-- <excludes>-->
<!-- &lt;!&ndash; lots of false-positives? TODO: investigate and fix &ndash;&gt;-->
<!-- <exclude>docs/**/*</exclude>-->
<!-- &lt;!&ndash; exclude for GitHub Actions &ndash;&gt;-->
<!-- <exclude>signing.key.asc</exclude>-->
<!-- </excludes>-->
<!-- <includes>-->
<!-- <include>pom.xml</include>-->
<!-- <include>maven-version-rules.xml</include>-->
<!-- <include>src/**/*</include>-->
<!-- </includes>-->
<!-- </configuration>-->
<!-- </plugin>-->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public Integer call() throws IOException {
.orElseThrow(DevcontainerJsonMissingException::new);
final var devcontainer = Devcontainer.parse(json);

if (options.executeInitializeCommand) {
if (options.executeInitializeCommand && Objects.nonNull(devcontainer.initializeCommand())) {
final var exitCode = runCommand(devcontainer.initializeCommand(), options.debug);
if (CommandLine.ExitCode.OK != exitCode) {
return exitCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import wtf.metio.devcontainer.Devcontainer;
import wtf.metio.ilo.compose.ComposeOptions;
import wtf.metio.ilo.shell.ShellOptions;
import wtf.metio.ilo.shell.ShellVolumeBehavior;

import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -22,6 +23,8 @@ final class DevcontainerOptionsMapper {

static ShellOptions shellOptions(final DevcontainerOptions options, final Devcontainer devcontainer) {
final var opts = new ShellOptions();
opts.interactive = true;
opts.missingVolumes = ShellVolumeBehavior.CREATE;
opts.debug = options.debug;
opts.pull = options.pull;
opts.removeImage = options.removeImage;
Expand All @@ -38,11 +41,13 @@ static ShellOptions shellOptions(final DevcontainerOptions options, final Devcon
.flatMap(Collection::stream)
.map(port -> port + ":" + port)
.toList();
opts.runtimeRunOptions = devcontainer.runArgs();
return opts;
}

static ComposeOptions composeOptions(final DevcontainerOptions options, final Devcontainer devcontainer, final Path devcontainerJson) {
final var opts = new ComposeOptions();
opts.interactive = true;
opts.file = Stream.ofNullable(devcontainer.dockerComposeFile())
.flatMap(Collection::stream)
.map(Paths::get)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.junit.jupiter.api.Test;
import wtf.metio.devcontainer.BuildBuilder;
import wtf.metio.devcontainer.DevcontainerBuilder;
import wtf.metio.ilo.shell.ShellVolumeBehavior;

import java.nio.file.Paths;
import java.util.List;
Expand Down Expand Up @@ -89,6 +90,48 @@ void shouldMapForwardPorts() {
assertIterableEquals(List.of("123:123", "456:456"), shellOptions.ports);
}

@Test
@DisplayName("maps the runArgs field")
void shouldMapRunArgs() {
// given
final var options = new DevcontainerOptions();
final var json = DevcontainerBuilder.builder().runArgs(List.of("--cap-add=SYS_PTRACE", "--security-opt")).create();

// when
final var shellOptions = shellOptions(options, json);

// then
assertIterableEquals(List.of("--cap-add=SYS_PTRACE", "--security-opt"), shellOptions.runtimeRunOptions);
}

@Test
@DisplayName("--interactive is set to true")
void shouldEnableInteractiveMode() {
// given
final var options = new DevcontainerOptions();
final var json = DevcontainerBuilder.builder().create();

// when
final var shellOptions = shellOptions(options, json);

// then
assertTrue(shellOptions.interactive);
}

@Test
@DisplayName("--missing-volumes is set to CREATE")
void shouldCreateMissingVolumes() {
// given
final var options = new DevcontainerOptions();
final var json = DevcontainerBuilder.builder().create();

// when
final var shellOptions = shellOptions(options, json);

// then
assertEquals(ShellVolumeBehavior.CREATE, shellOptions.missingVolumes);
}

@Test
@DisplayName("sets the default context in case none is specified")
void shouldUseDefaultForMissingContext() {
Expand Down Expand Up @@ -157,6 +200,20 @@ void shouldMapService() {
assertEquals(json.service(), composeOptions.service);
}

@Test
@DisplayName("--interactive is set to true")
void shouldEnableInteractiveMode() {
// given
final var options = new DevcontainerOptions();
final var json = DevcontainerBuilder.builder().create();

// when
final var composeOptions = composeOptions(options, json, Paths.get("."));

// then
assertTrue(composeOptions.interactive);
}

}

}