forked from airbytehq/airbyte
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prepare clean mount management (airbytehq#126)
- Loading branch information
1 parent
5d696f0
commit f344ecb
Showing
40 changed files
with
533 additions
and
246 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
.dockerignore | ||
.git | ||
.idea | ||
.gradle | ||
**/build | ||
**/node_modules | ||
Dockerfile.* | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
93 changes: 93 additions & 0 deletions
93
dataline-config/src/main/java/io/dataline/config/EnvConfigs.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2020 Dataline | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package io.dataline.config; | ||
|
||
import java.nio.file.Path; | ||
import java.util.function.Function; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class EnvConfigs implements Configs { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(EnvConfigs.class); | ||
|
||
public static final String WORKSPACE_ROOT = "WORKSPACE_ROOT"; | ||
public static final String WORKSPACE_DOCKER_MOUNT = "WORKSPACE_DOCKER_MOUNT"; | ||
public static final String CONFIG_ROOT = "CONFIG_ROOT"; | ||
public static final String DOCKER_NETWORK = "DOCKER_NETWORK"; | ||
|
||
public static final String DEFAULT_NETWORK = "host"; | ||
|
||
private final Function<String, String> getEnv; | ||
|
||
public EnvConfigs() { | ||
this(System::getenv); | ||
} | ||
|
||
EnvConfigs(final Function<String, String> getEnv) { | ||
this.getEnv = getEnv; | ||
} | ||
|
||
@Override | ||
public Path getConfigRoot() { | ||
return getPath(CONFIG_ROOT); | ||
} | ||
|
||
@Override | ||
public Path getWorkspaceRoot() { | ||
return getPath(WORKSPACE_ROOT); | ||
} | ||
|
||
@Override | ||
public String getWorkspaceDockerMount() { | ||
final String mount = getEnv.apply(WORKSPACE_DOCKER_MOUNT); | ||
|
||
if (mount != null) { | ||
return mount; | ||
} | ||
|
||
LOGGER.info(WORKSPACE_DOCKER_MOUNT + " not found, defaulting to " + WORKSPACE_ROOT); | ||
return getWorkspaceRoot().toString(); | ||
} | ||
|
||
@Override | ||
public String getDockerNetwork() { | ||
final String network = getEnv.apply(DOCKER_NETWORK); | ||
if (network != null) { | ||
return network; | ||
} | ||
|
||
LOGGER.info(DOCKER_NETWORK + " not found, defaulting to " + DEFAULT_NETWORK); | ||
return DEFAULT_NETWORK; | ||
} | ||
|
||
private Path getPath(final String name) { | ||
final String value = getEnv.apply(name); | ||
if (value == null) { | ||
throw new IllegalArgumentException("Env variable not defined: " + name); | ||
} | ||
return Path.of(value); | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
dataline-config/src/test/java/io/dataline/config/EnvConfigsTest.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2020 Dataline | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package io.dataline.config; | ||
|
||
import static org.mockito.Mockito.when; | ||
|
||
import java.nio.file.Paths; | ||
import java.util.function.Function; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
|
||
class EnvConfigsTest { | ||
|
||
private Function<String, String> function; | ||
private EnvConfigs config; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
function = Mockito.mock(Function.class); | ||
config = new EnvConfigs(function); | ||
} | ||
|
||
@Test | ||
void ensureGetEnvBehavior() { | ||
Assertions.assertNull(System.getenv("MY_RANDOM_VAR_1234")); | ||
} | ||
|
||
@Test | ||
void testWorkspaceRoot() { | ||
when(function.apply(EnvConfigs.WORKSPACE_ROOT)).thenReturn(null); | ||
Assertions.assertThrows(IllegalArgumentException.class, () -> config.getWorkspaceRoot()); | ||
|
||
when(function.apply(EnvConfigs.WORKSPACE_ROOT)).thenReturn("abc/def"); | ||
Assertions.assertEquals(Paths.get("abc/def"), config.getWorkspaceRoot()); | ||
} | ||
|
||
@Test | ||
void testConfigRoot() { | ||
when(function.apply(EnvConfigs.CONFIG_ROOT)).thenReturn(null); | ||
Assertions.assertThrows(IllegalArgumentException.class, () -> config.getConfigRoot()); | ||
|
||
when(function.apply(EnvConfigs.CONFIG_ROOT)).thenReturn("a/b"); | ||
Assertions.assertEquals(Paths.get("a/b"), config.getConfigRoot()); | ||
} | ||
|
||
@Test | ||
void testGetDockerMount() { | ||
when(function.apply(EnvConfigs.WORKSPACE_DOCKER_MOUNT)).thenReturn(null); | ||
when(function.apply(EnvConfigs.WORKSPACE_ROOT)).thenReturn("abc/def"); | ||
Assertions.assertEquals("abc/def", config.getWorkspaceDockerMount()); | ||
|
||
when(function.apply(EnvConfigs.WORKSPACE_DOCKER_MOUNT)).thenReturn("root"); | ||
when(function.apply(EnvConfigs.WORKSPACE_ROOT)).thenReturn(null); | ||
Assertions.assertEquals("root", config.getWorkspaceDockerMount()); | ||
|
||
when(function.apply(EnvConfigs.WORKSPACE_DOCKER_MOUNT)).thenReturn(null); | ||
when(function.apply(EnvConfigs.WORKSPACE_ROOT)).thenReturn(null); | ||
Assertions.assertThrows(IllegalArgumentException.class, () -> config.getWorkspaceDockerMount()); | ||
} | ||
|
||
@Test | ||
void testDockerNetwork() { | ||
when(function.apply(EnvConfigs.DOCKER_NETWORK)).thenReturn(null); | ||
Assertions.assertEquals("host", config.getDockerNetwork()); | ||
|
||
when(function.apply(EnvConfigs.DOCKER_NETWORK)).thenReturn("abc"); | ||
Assertions.assertEquals("abc", config.getDockerNetwork()); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.