Skip to content

Commit f344ecb

Browse files
Prepare clean mount management (airbytehq#126)
1 parent 5d696f0 commit f344ecb

File tree

40 files changed

+533
-246
lines changed

40 files changed

+533
-246
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.dockerignore
22
.git
33
.idea
4+
.gradle
45
**/build
56
**/node_modules
67
Dockerfile.*

.env

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ DATABASE_USER=docker
44
DATABASE_PASSWORD=docker
55
DATABASE_DB=dataline
66
DATABASE_URL=jdbc:postgresql://db:5432/dataline
7-
CONFIG_PERSISTENCE_ROOT=data/config
7+
CONFIG_ROOT=data/config
8+
WORKSPACE_ROOT=/tmp/workspace

Dockerfile.build

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@
33
#####################
44
FROM ubuntu:20.04 AS build-base
55

6+
WORKDIR /code
7+
8+
ENV DEBIAN_FRONTEND noninteractive
9+
610
# Install tools
711
RUN apt-get update && apt-get -y install curl
812

913
# Setup Node & Java
1014
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash -
1115
RUN apt-get update && apt-get -y install \
1216
nodejs \
13-
openjdk-14-jdk
17+
openjdk-14-jdk \
18+
docker.io
1419

1520
#######################
1621
# Prepare project env #
@@ -29,6 +34,8 @@ RUN ./gradlew build --no-daemon -g /home/gradle/.gradle
2934
###################
3035
FROM build-project AS build
3136

37+
WORKDIR /code
38+
3239
# Copy code, etc.
3340
COPY . /code
3441

dataline-config-persistence/src/main/java/io/dataline/config/persistence/DefaultConfigPersistence.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,14 @@
4343

4444
// we force all interaction with disk storage to be effectively single threaded.
4545
public class DefaultConfigPersistence implements ConfigPersistence {
46+
4647
private static final Object lock = new Object();
4748

4849
private final ObjectMapper objectMapper;
4950
private final JsonSchemaValidation jsonSchemaValidation;
50-
private final String storageRoot;
51+
private final Path storageRoot;
5152

52-
public DefaultConfigPersistence(String storageRoot) {
53+
public DefaultConfigPersistence(Path storageRoot) {
5354
this.storageRoot = storageRoot;
5455
jsonSchemaValidation = new JsonSchemaValidation();
5556
objectMapper = new ObjectMapper();
@@ -145,7 +146,7 @@ private Set<Path> getFiles(PersistenceConfigType persistenceConfigType) {
145146
}
146147

147148
private Path getConfigDirectory(PersistenceConfigType persistenceConfigType) {
148-
return Path.of(storageRoot).resolve(persistenceConfigType.toString());
149+
return storageRoot.resolve(persistenceConfigType.toString());
149150
}
150151

151152
private Path getConfigPath(PersistenceConfigType persistenceConfigType, String configId) {

dataline-config-persistence/src/test/java/io/dataline/config/persistence/DefaultConfigPersistenceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class DefaultConfigPersistenceTest {
4747
@BeforeEach
4848
void setUp() throws IOException {
4949
rootPath = Files.createTempDirectory(DefaultConfigPersistenceTest.class.getName());
50-
configPersistence = new DefaultConfigPersistence(rootPath.toString());
50+
configPersistence = new DefaultConfigPersistence(rootPath);
5151
}
5252

5353
private StandardSource generateStandardSource() {
Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@
2222
* SOFTWARE.
2323
*/
2424

25-
package io.dataline.workers.singer.postgres_tap;
25+
package io.dataline.config;
2626

27-
import io.dataline.integrations.Integrations;
28-
import io.dataline.workers.singer.SingerDiscoverSchemaWorker;
27+
import java.nio.file.Path;
2928

30-
public class SingerPostgresTapDiscoverWorker extends SingerDiscoverSchemaWorker {
29+
public interface Configs {
3130

32-
public SingerPostgresTapDiscoverWorker() {
33-
super(Integrations.POSTGRES_TAP.getSyncImage());
34-
}
31+
Path getConfigRoot();
32+
33+
Path getWorkspaceRoot();
34+
35+
String getWorkspaceDockerMount();
36+
37+
String getDockerNetwork();
3538
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2020 Dataline
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
package io.dataline.config;
26+
27+
import java.nio.file.Path;
28+
import java.util.function.Function;
29+
import org.slf4j.Logger;
30+
import org.slf4j.LoggerFactory;
31+
32+
public class EnvConfigs implements Configs {
33+
34+
private static final Logger LOGGER = LoggerFactory.getLogger(EnvConfigs.class);
35+
36+
public static final String WORKSPACE_ROOT = "WORKSPACE_ROOT";
37+
public static final String WORKSPACE_DOCKER_MOUNT = "WORKSPACE_DOCKER_MOUNT";
38+
public static final String CONFIG_ROOT = "CONFIG_ROOT";
39+
public static final String DOCKER_NETWORK = "DOCKER_NETWORK";
40+
41+
public static final String DEFAULT_NETWORK = "host";
42+
43+
private final Function<String, String> getEnv;
44+
45+
public EnvConfigs() {
46+
this(System::getenv);
47+
}
48+
49+
EnvConfigs(final Function<String, String> getEnv) {
50+
this.getEnv = getEnv;
51+
}
52+
53+
@Override
54+
public Path getConfigRoot() {
55+
return getPath(CONFIG_ROOT);
56+
}
57+
58+
@Override
59+
public Path getWorkspaceRoot() {
60+
return getPath(WORKSPACE_ROOT);
61+
}
62+
63+
@Override
64+
public String getWorkspaceDockerMount() {
65+
final String mount = getEnv.apply(WORKSPACE_DOCKER_MOUNT);
66+
67+
if (mount != null) {
68+
return mount;
69+
}
70+
71+
LOGGER.info(WORKSPACE_DOCKER_MOUNT + " not found, defaulting to " + WORKSPACE_ROOT);
72+
return getWorkspaceRoot().toString();
73+
}
74+
75+
@Override
76+
public String getDockerNetwork() {
77+
final String network = getEnv.apply(DOCKER_NETWORK);
78+
if (network != null) {
79+
return network;
80+
}
81+
82+
LOGGER.info(DOCKER_NETWORK + " not found, defaulting to " + DEFAULT_NETWORK);
83+
return DEFAULT_NETWORK;
84+
}
85+
86+
private Path getPath(final String name) {
87+
final String value = getEnv.apply(name);
88+
if (value == null) {
89+
throw new IllegalArgumentException("Env variable not defined: " + name);
90+
}
91+
return Path.of(value);
92+
}
93+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2020 Dataline
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
package io.dataline.config;
26+
27+
import static org.mockito.Mockito.when;
28+
29+
import java.nio.file.Paths;
30+
import java.util.function.Function;
31+
import org.junit.jupiter.api.Assertions;
32+
import org.junit.jupiter.api.BeforeEach;
33+
import org.junit.jupiter.api.Test;
34+
import org.mockito.Mockito;
35+
36+
class EnvConfigsTest {
37+
38+
private Function<String, String> function;
39+
private EnvConfigs config;
40+
41+
@BeforeEach
42+
void setUp() {
43+
function = Mockito.mock(Function.class);
44+
config = new EnvConfigs(function);
45+
}
46+
47+
@Test
48+
void ensureGetEnvBehavior() {
49+
Assertions.assertNull(System.getenv("MY_RANDOM_VAR_1234"));
50+
}
51+
52+
@Test
53+
void testWorkspaceRoot() {
54+
when(function.apply(EnvConfigs.WORKSPACE_ROOT)).thenReturn(null);
55+
Assertions.assertThrows(IllegalArgumentException.class, () -> config.getWorkspaceRoot());
56+
57+
when(function.apply(EnvConfigs.WORKSPACE_ROOT)).thenReturn("abc/def");
58+
Assertions.assertEquals(Paths.get("abc/def"), config.getWorkspaceRoot());
59+
}
60+
61+
@Test
62+
void testConfigRoot() {
63+
when(function.apply(EnvConfigs.CONFIG_ROOT)).thenReturn(null);
64+
Assertions.assertThrows(IllegalArgumentException.class, () -> config.getConfigRoot());
65+
66+
when(function.apply(EnvConfigs.CONFIG_ROOT)).thenReturn("a/b");
67+
Assertions.assertEquals(Paths.get("a/b"), config.getConfigRoot());
68+
}
69+
70+
@Test
71+
void testGetDockerMount() {
72+
when(function.apply(EnvConfigs.WORKSPACE_DOCKER_MOUNT)).thenReturn(null);
73+
when(function.apply(EnvConfigs.WORKSPACE_ROOT)).thenReturn("abc/def");
74+
Assertions.assertEquals("abc/def", config.getWorkspaceDockerMount());
75+
76+
when(function.apply(EnvConfigs.WORKSPACE_DOCKER_MOUNT)).thenReturn("root");
77+
when(function.apply(EnvConfigs.WORKSPACE_ROOT)).thenReturn(null);
78+
Assertions.assertEquals("root", config.getWorkspaceDockerMount());
79+
80+
when(function.apply(EnvConfigs.WORKSPACE_DOCKER_MOUNT)).thenReturn(null);
81+
when(function.apply(EnvConfigs.WORKSPACE_ROOT)).thenReturn(null);
82+
Assertions.assertThrows(IllegalArgumentException.class, () -> config.getWorkspaceDockerMount());
83+
}
84+
85+
@Test
86+
void testDockerNetwork() {
87+
when(function.apply(EnvConfigs.DOCKER_NETWORK)).thenReturn(null);
88+
Assertions.assertEquals("host", config.getDockerNetwork());
89+
90+
when(function.apply(EnvConfigs.DOCKER_NETWORK)).thenReturn("abc");
91+
Assertions.assertEquals("abc", config.getDockerNetwork());
92+
}
93+
}

dataline-integrations/singer/csv/destination/Dockerfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,4 @@ COPY requirements.txt .
1111
RUN python -m pip install --upgrade pip && \
1212
pip install -r requirements.txt
1313

14-
WORKDIR /singer/data
15-
1614
ENTRYPOINT ["target-csv"]

dataline-integrations/singer/exchangerateapi_io/source/Dockerfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,4 @@ COPY requirements.txt .
1111
RUN python -m pip install --upgrade pip && \
1212
pip install -r requirements.txt
1313

14-
WORKDIR /singer/data
15-
1614
ENTRYPOINT ["tap-exchangeratesapi"]

0 commit comments

Comments
 (0)