forked from opensearch-project/opensearch-migrations
-
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.
Extract some of the build logic to build a docker image for RFS and m…
…ove it to DocumentFromSnapshotMigration Signed-off-by: Greg Schohn <[email protected]>
- Loading branch information
1 parent
8733c01
commit a9b6709
Showing
12 changed files
with
201 additions
and
85 deletions.
There are no files selected for viewing
112 changes: 112 additions & 0 deletions
112
DocumentsFromSnapshotMigration/build-preloaded-source-image.gradle
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,112 @@ | ||
import com.bmuschko.gradle.docker.tasks.container.* | ||
import com.github.dockerjava.core.DefaultDockerClientConfig | ||
import com.github.dockerjava.core.DockerClientImpl | ||
import com.github.dockerjava.httpclient5.ApacheDockerHttpClient | ||
|
||
def createDockerClient() { | ||
def config = DefaultDockerClientConfig.createDefaultConfigBuilder().build() | ||
def httpClient = new ApacheDockerHttpClient.Builder() | ||
.dockerHost(config.getDockerHost()) | ||
.sslConfig(config.getSSLConfig()) | ||
.maxConnections(100) | ||
.build() | ||
|
||
return DockerClientImpl.getInstance(config, httpClient) | ||
} | ||
|
||
def uniqueId = UUID.randomUUID(); | ||
def myNetworkName = "rfs-preload-source-${uniqueId}"; | ||
def createNetworkTask = task createNetwork(type: Exec) { | ||
commandLine 'docker', 'network', 'create', myNetworkName | ||
doLast { | ||
println 'Network created' | ||
} | ||
} | ||
task createInitialElasticsearchContainer(type: DockerCreateContainer) { | ||
dependsOn createNetwork, buildDockerImage_emptyElasticsearchSource_7_17 | ||
targetImageId 'migrations/emptyElasticsearchSource_7_17:latest' | ||
containerName = "elasticsearch-${uniqueId}" | ||
hostConfig.network = myNetworkName | ||
hostConfig.dns = ['elasticsearch'] | ||
networkAliases = ['elasticsearch'] | ||
hostName = 'elasticsearch' | ||
} | ||
|
||
def startSourceTask = task startInitialElasticsearchContainer(type: DockerStartContainer) { | ||
dependsOn createInitialElasticsearchContainer | ||
targetContainerId createInitialElasticsearchContainer.getContainerId() | ||
} | ||
|
||
task createClientContainer(type: DockerCreateContainer) { | ||
dependsOn startInitialElasticsearchContainer, buildDockerImage_trafficGenerator | ||
targetImageId 'migrations/osb_traffic_generator:latest' | ||
containerName = "traffic-generator-container-${uniqueId}" | ||
hostConfig.network = myNetworkName | ||
cmd = ['default_osb_test_workloads', "http://elasticsearch:9200"] | ||
} | ||
|
||
def startClientTask = task startClientContainer(type: DockerStartContainer) { | ||
dependsOn createClientContainer | ||
targetContainerId createClientContainer.getContainerId() | ||
} | ||
|
||
task waitClientContainer(type: DockerWaitContainer) { | ||
dependsOn startClientContainer | ||
targetContainerId createClientContainer.getContainerId() | ||
} | ||
|
||
// Task to commit the source container to create a new image that will include the loaded data | ||
def sourceContainerCommitTask = task commitSourceContainer() { | ||
dependsOn waitClientContainer | ||
|
||
doLast { | ||
def client = createDockerClient() | ||
def containerId = createInitialElasticsearchContainer.getContainerId().get() | ||
|
||
client.commitCmd(containerId) | ||
.withRepository("elasticsearch_rfs_source") | ||
.withTag("latest") | ||
.exec() | ||
} | ||
} | ||
|
||
task removeClientContainer(type: DockerRemoveContainer) { | ||
dependsOn waitClientContainer | ||
targetContainerId createClientContainer.getContainerId() | ||
} | ||
startClientTask.finalizedBy(removeClientContainer) | ||
|
||
// Task to stop and remove the primary container | ||
task stopInitialElasticsearchContainer(type: DockerStopContainer) { | ||
dependsOn commitSourceContainer | ||
targetContainerId createInitialElasticsearchContainer.getContainerId() | ||
} | ||
|
||
task removeInitialElasticsearchContainer(type: DockerRemoveContainer) { | ||
dependsOn stopInitialElasticsearchContainer | ||
targetContainerId createInitialElasticsearchContainer.getContainerId() | ||
} | ||
startSourceTask.finalizedBy(removeInitialElasticsearchContainer) | ||
|
||
def deleteNetworkTask = task deleteNetwork(type: Exec) { | ||
mustRunAfter removeInitialElasticsearchContainer, removeClientContainer | ||
commandLine 'docker', 'network', 'rm', myNetworkName | ||
doLast { | ||
println 'Custom network removed' | ||
} | ||
ignoreExitValue = true | ||
} | ||
createNetworkTask.finalizedBy(deleteNetworkTask) | ||
|
||
// Orchestration task | ||
task orchestrateContainers { | ||
dependsOn removeInitialElasticsearchContainer | ||
doLast { | ||
println 'Primary container modified, committed as a new image, and cleaned up.' | ||
println 'Client container executed, waited for completion, and cleaned up.' | ||
} | ||
} | ||
|
||
task buildDockerImage_elasticsearchRFSSource { | ||
dependsOn sourceContainerCommitTask | ||
} |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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