Skip to content

Commit

Permalink
Bmoric/remove docker compose for build (airbytehq#7500)
Browse files Browse the repository at this point in the history
This making the build using a gradle plugin instead of using docker-compose build.
It aims to make the build to be more incremental as described in airbytehq#7306

Building the docker image don't rely on docker-compose anymore.
The docker build step is isolated into a dedicated folder (in order to make sure that gradle plugin don't recompute the build of the docker container)
Gradle is responsible for copying the files that docker needs to build its image.
That removes the need of having a dockerignore file.
This might not be effective until airbytehq#7539 is solved.
  • Loading branch information
benmoriceau authored and schlattk committed Jan 4, 2022
1 parent ebd4795 commit 0d60f27
Show file tree
Hide file tree
Showing 30 changed files with 210 additions and 77 deletions.
2 changes: 2 additions & 0 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ serialize =

[bumpversion:file:.env]

[bumpversion:file:airbyte-migration/Dockerfile]

[bumpversion:file:airbyte-server/Dockerfile]

[bumpversion:file:airbyte-workers/Dockerfile]
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ jobs:
EOF
- name: Build Platform Docker Images
run: SUB_BUILD=PLATFORM ./gradlew --no-daemon composebuild --scan
run: SUB_BUILD=PLATFORM ./gradlew --no-daemon assemble --scan

- name: Run End-to-End Frontend Tests
run: ./tools/bin/e2e_test.sh
Expand Down Expand Up @@ -457,7 +457,7 @@ jobs:
HOME: /home/runner

- name: Build Platform Docker Images
run: SUB_BUILD=PLATFORM ./gradlew composeBuild --scan
run: SUB_BUILD=PLATFORM ./gradlew assemble --scan

- name: Run Kubernetes End-to-End Acceptance Tests
env:
Expand Down
6 changes: 3 additions & 3 deletions airbyte-cli/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
plugins {
id "airbyte-docker"
}
Task dockerBuildTask = getDockerBuildTask("cli", "$project.projectDir")
dockerBuildTask.dependsOn(copyDocker)
assemble.dependsOn(dockerBuildTask)
3 changes: 0 additions & 3 deletions airbyte-config/init/.dockerignore

This file was deleted.

2 changes: 1 addition & 1 deletion airbyte-config/init/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ WORKDIR /app

# the sole purpose of this image is to seed the data volume with the default data
# that the app should have when it is first installed.
COPY scripts scripts
COPY bin/scripts scripts
11 changes: 11 additions & 0 deletions airbyte-config/init/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,14 @@ dependencies {
implementation project(':airbyte-commons-docker')
implementation project(':airbyte-json-validation')
}

task copyScripts(type: Copy) {
dependsOn copyDocker

from('scripts')
into 'build/docker/bin/scripts'
}

Task dockerBuildTask = getDockerBuildTask("init", "$project.projectDir")
dockerBuildTask.dependsOn(copyScripts)
assemble.dependsOn(dockerBuildTask)
2 changes: 0 additions & 2 deletions airbyte-db/lib/.dockerignore

This file was deleted.

2 changes: 1 addition & 1 deletion airbyte-db/lib/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM postgres:13-alpine

COPY src/main/resources/init.sql /docker-entrypoint-initdb.d/000_init.sql
COPY bin/init.sql /docker-entrypoint-initdb.d/000_init.sql
13 changes: 13 additions & 0 deletions airbyte-db/lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,16 @@ task(dumpJobsSchema, dependsOn: 'classes', type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
args 'jobs', 'dump_schema'
}

task copyInitSql(type: Copy) {
dependsOn copyDocker

from('src/main/resources') {
include 'init.sql'
}
into 'build/docker/bin'
}

Task dockerBuildTask = getDockerBuildTask("db", "$project.projectDir")
dockerBuildTask.dependsOn(copyInitSql)
assemble.dependsOn(dockerBuildTask)
3 changes: 0 additions & 3 deletions airbyte-migration/.dockerignore

This file was deleted.

2 changes: 1 addition & 1 deletion airbyte-migration/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ENV APPLICATION airbyte-migration
WORKDIR /app

# Move and run scheduler
COPY build/distributions/${APPLICATION}*.tar ${APPLICATION}.tar
COPY bin/${APPLICATION}-0.30.31-alpha.tar ${APPLICATION}.tar

RUN tar xf ${APPLICATION}.tar --strip-components=1

Expand Down
13 changes: 13 additions & 0 deletions airbyte-migration/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,16 @@ application {
mainClass = 'io.airbyte.migrate.MigrationRunner'
}

task copyGeneratedTar(type: Copy) {
dependsOn distTar
dependsOn copyDocker

from('build/distributions') {
include 'airbyte-migration-*.tar'
}
into 'build/docker/bin'
}

Task dockerBuildTask = getDockerBuildTask("migration", "$project.projectDir")
dockerBuildTask.dependsOn(copyGeneratedTar)
assemble.dependsOn(dockerBuildTask)
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.util.function.Function;
import java.util.function.Supplier;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.http.client.utils.URIBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
3 changes: 0 additions & 3 deletions airbyte-scheduler/app/.dockerignore

This file was deleted.

2 changes: 1 addition & 1 deletion airbyte-scheduler/app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ENV APPLICATION airbyte-scheduler

WORKDIR /app

ADD build/distributions/${APPLICATION}-0.30.31-alpha.tar /app
ADD bin/${APPLICATION}-0.30.31-alpha.tar /app

# wait for upstream dependencies to become available before starting server
ENTRYPOINT ["/bin/bash", "-c", "${APPLICATION}-0.30.31-alpha/bin/${APPLICATION}"]
14 changes: 14 additions & 0 deletions airbyte-scheduler/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,17 @@ run {
environment "TEMPORAL_HOST", "localhost:7233"

}

task copyGeneratedTar(type: Copy) {
dependsOn copyDocker
dependsOn distTar

from('build/distributions') {
include 'airbyte-scheduler-*.tar'
}
into 'build/docker/bin'
}

Task dockerBuildTask = getDockerBuildTask("scheduler", "$project.projectDir")
dockerBuildTask.dependsOn(copyGeneratedTar)
assemble.dependsOn(dockerBuildTask)
3 changes: 0 additions & 3 deletions airbyte-server/.dockerignore

This file was deleted.

2 changes: 1 addition & 1 deletion airbyte-server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ENV APPLICATION airbyte-server

WORKDIR /app

ADD build/distributions/${APPLICATION}-0.30.31-alpha.tar /app
ADD bin/${APPLICATION}-0.30.31-alpha.tar /app

# wait for upstream dependencies to become available before starting server
ENTRYPOINT ["/bin/bash", "-c", "${APPLICATION}-0.30.31-alpha/bin/${APPLICATION}"]
14 changes: 14 additions & 0 deletions airbyte-server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,17 @@ run {
environment "AIRBYTE_ROLE", System.getenv('AIRBYTE_ROLE')
environment "TEMPORAL_HOST", "localhost:7233"
}

task copyGeneratedTar(type: Copy) {
dependsOn copyDocker
dependsOn distTar

from('build/distributions') {
include 'airbyte-server-*.tar'
}
into 'build/docker/bin'
}

Task dockerBuildTask = getDockerBuildTask("server", "$project.projectDir")
dockerBuildTask.dependsOn(copyGeneratedTar)
assemble.dependsOn(dockerBuildTask)
4 changes: 0 additions & 4 deletions airbyte-webapp/.dockerignore

This file was deleted.

8 changes: 3 additions & 5 deletions airbyte-webapp/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ FROM nginx:1.19-alpine as webapp

EXPOSE 80

COPY build/docs docs/
# docs get copied twice because npm gradle plugin ignores output dir.
COPY build /usr/share/nginx/html
RUN rm -rf /usr/share/nginx/html/docs
COPY nginx/default.conf.template /etc/nginx/templates/default.conf.template
COPY bin/docs docs/
COPY bin/build /usr/share/nginx/html
COPY bin/nginx/default.conf.template /etc/nginx/templates/default.conf.template
31 changes: 29 additions & 2 deletions airbyte-webapp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,38 @@ task test(type: NpmTask) {
assemble.dependsOn npm_run_build
build.finalizedBy test

task copyBuild(type: Copy) {
dependsOn copyDocker

from "${project.projectDir}/build"
into "build/docker/bin/build"
exclude ".docker"
exclude "docker"
}

task copyDocs(type: Copy) {
from "${System.getProperty("user.dir")}/docs/integrations"
into "${buildDir}/docs/integrations"
dependsOn copyDocker

from "${project.rootProject.projectDir}/docs/integrations"
into "build/docker/bin/docs/integrations"
duplicatesStrategy DuplicatesStrategy.INCLUDE
}

task copyNginx(type: Copy) {
dependsOn copyDocker

from "${project.projectDir}/nginx"
into "build/docker/bin/nginx"
}

copyBuild.dependsOn npm_run_build
copyNginx.dependsOn npm_run_build
copyDocs.dependsOn npm_run_build
assemble.dependsOn copyDocs
copyDocker.dependsOn(npm_run_build)

Task dockerBuildTask = getDockerBuildTask("webapp", "$project.projectDir")
dockerBuildTask.dependsOn(copyBuild)
dockerBuildTask.dependsOn(copyNginx)
dockerBuildTask.dependsOn(copyDocs)
assemble.dependsOn(dockerBuildTask)
2 changes: 1 addition & 1 deletion airbyte-workers/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ENV APPLICATION airbyte-workers
WORKDIR /app

# Move worker app
ADD build/distributions/${APPLICATION}-0.30.31-alpha.tar /app
ADD bin/${APPLICATION}-0.30.31-alpha.tar /app

# wait for upstream dependencies to become available before starting server
ENTRYPOINT ["/bin/bash", "-c", "${APPLICATION}-0.30.31-alpha/bin/${APPLICATION}"]
14 changes: 14 additions & 0 deletions airbyte-workers/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,17 @@ application {
mainClass = mainClassName
applicationDefaultJvmArgs = ['-XX:MaxRAMPercentage=75.0']
}

task copyGeneratedTar(type: Copy) {
dependsOn copyDocker
dependsOn distTar

from('build/distributions') {
include 'airbyte-workers-*.tar'
}
into 'build/docker/bin'
}

Task dockerBuildTask = getDockerBuildTask("worker", "$project.projectDir")
dockerBuildTask.dependsOn(copyGeneratedTar)
assemble.dependsOn(dockerBuildTask)
75 changes: 38 additions & 37 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage

buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'com.bmuschko:gradle-docker-plugin:7.1.0'
}
}

plugins {
id 'base'
id 'pmd'
Expand Down Expand Up @@ -112,27 +125,36 @@ spotless {
}
check.dependsOn 'spotlessApply'

@SuppressWarnings('GroovyAssignabilityCheck')
def Task getDockerBuildTask(String artifactName, String projectDir) {
return task ("buildDockerImage-$artifactName" (type: DockerBuildImage) {
def buildTag = System.getenv('VERSION') ?: 'dev'
def buildPlatform = System.getenv('DOCKER_BUILD_PLATFORM') ?: 'linux/amd64'
def jdkVersion = System.getenv('JDK_VERSION') ?: '14.0.2'
def buildArch = System.getenv('DOCKER_BUILD_ARCH') ?: 'amd64'

inputDir = file("$projectDir/build/docker")
platform = buildPlatform
images.add("airbyte/$artifactName:$buildTag")
buildArgs.put('JDK_VERSION', jdkVersion)
buildArgs.put('DOCKER_BUILD_ARCH', buildArch)
})
}

allprojects {
apply plugin: 'base'
apply plugin: 'com.bmuschko.docker-remote-api'

afterEvaluate { project ->
def composeDeps = [
":airbyte-config:init",
":airbyte-db:lib",
":airbyte-migration",
":airbyte-scheduler:app",
":airbyte-workers",
":airbyte-server",
":airbyte-webapp",
].toSet().asImmutable()

if (project.getPath() in composeDeps) {
composeBuild.dependsOn(project.getPath() + ':assemble')
}
task copyDocker(type: Copy) {
delete "build/docker"

from "${project.projectDir}/Dockerfile"
into "build/docker/"
}
}

allprojects {
apply plugin: 'base'

// by default gradle uses directory as the project name. That works very well in a single project environment but
// projects clobber each other in an environments with subprojects when projects are in directories named identically.
def sub = rootDir.relativePath(projectDir.parentFile).replace('/', '.')
Expand Down Expand Up @@ -234,6 +256,7 @@ subprojects {
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.7.2'
testImplementation 'org.mockito:mockito-junit-jupiter:3.12.4'
testImplementation 'org.assertj:assertj-core:3.21.0'

}

tasks.withType(Tar) {
Expand All @@ -245,28 +268,6 @@ subprojects {
}
}

task composeBuild {
def buildTag = System.getenv('VERSION') ?: 'dev'
def buildPlatform = System.getenv('DOCKER_BUILD_PLATFORM') ?: 'linux/amd64'
def buildArch = System.getenv('DOCKER_BUILD_ARCH') ?: 'amd64'
def jdkVersion = System.getenv('JDK_VERSION') ?: '14.0.2'
def dockerComposeFile = buildArch == 'arm64' ? 'docker-compose.build-m1.yaml' : 'docker-compose.build.yaml'
doFirst {
exec {
workingDir rootDir
commandLine 'docker-compose', '-f', dockerComposeFile, 'build', '--parallel', '--quiet'
environment 'VERSION', buildTag
environment 'DOCKER_BUILD_PLATFORM', buildPlatform
environment 'DOCKER_BUILD_ARCH', buildArch
environment 'JDK_VERSION', jdkVersion
}
}
}

if (!System.getenv().containsKey("SUB_BUILD") || System.getenv().get("SUB_BUILD") == "PLATFORM") {
build.dependsOn(composeBuild)
}

task('generate') {
dependsOn subprojects.collect { it.getTasksByName('generateProtocolClassFiles', true) }
dependsOn subprojects.collect { it.getTasksByName('generateJsonSchema2Pojo', true) }
Expand Down
1 change: 1 addition & 0 deletions docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@
* [Contributing to Airbyte](contributing-to-airbyte/README.md)
* [Code of Conduct](contributing-to-airbyte/code-of-conduct.md)
* [Developing Locally](contributing-to-airbyte/developing-locally.md)
* [Developing on Docker](contributing-to-airbyte/developing-on-docker.md)
* [Developing on Kubernetes](contributing-to-airbyte/developing-on-kubernetes.md)
* [Monorepo Python Development](contributing-to-airbyte/monorepo-python-development.md)
* [Code Style](contributing-to-airbyte/code-style.md)
Expand Down
Loading

0 comments on commit 0d60f27

Please sign in to comment.