Skip to content

Commit

Permalink
Revert "Revert "Bmoric/remove docker compose for build (#7500)" (#7698)…
Browse files Browse the repository at this point in the history
…" (#7746)

This reverts commit 797d11a.

Restore the removal of the docker compose file
  • Loading branch information
benmoriceau committed Nov 8, 2021
1 parent 6f12778 commit 42b378f
Show file tree
Hide file tree
Showing 31 changed files with 196 additions and 76 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 @@ -5,4 +5,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.34-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)
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.34-alpha.tar /app
ADD bin/${APPLICATION}-0.30.34-alpha.tar /app

# wait for upstream dependencies to become available before starting server
ENTRYPOINT ["/bin/bash", "-c", "${APPLICATION}-0.30.34-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.34-alpha.tar /app
ADD bin/${APPLICATION}-0.30.34-alpha.tar /app

# wait for upstream dependencies to become available before starting server
ENTRYPOINT ["/bin/bash", "-c", "${APPLICATION}-0.30.34-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.

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

EXPOSE 80

COPY build /usr/share/nginx/html
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.34-alpha.tar /app
ADD bin/${APPLICATION}-0.30.34-alpha.tar /app

# wait for upstream dependencies to become available before starting server
ENTRYPOINT ["/bin/bash", "-c", "${APPLICATION}-0.30.34-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)
59 changes: 22 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 @@ -133,26 +146,19 @@ def Task getDockerBuildTask(String artifactName, String projectDir) {
}

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 @@ -254,6 +260,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 @@ -265,28 +272,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 @@ -199,6 +199,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
43 changes: 43 additions & 0 deletions docs/contributing-to-airbyte/developing-on-docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Developing on docker

## Incrementality

The docker build is fully incremental for the platform build, which means that it will only build an image if it is needed. We need to keep it that
way.
A task generator, `getDockerBuildTask`, is available for building a docker image for any given module. Behind the scene, it will generate a
task which will run the build of a docker image in a specific folder. The goal is to make sure that we have an isolated
context which helps with incrementality. All files that need to be present in the docker image will need to be copy into this folder. The generate
method takes 2 arguments:
- The image name, for example if `foo` is given as an image name, the image `airbyte/foo` will be created
- The project directory folder. It is needed because the `getDockerBuildTask` is declared in the rootProject

## Adding a new docker build

Once you have a `Dockerfile`, generating the docker image is done in the following way:
- specify the artifact name and the project directory,
- make sure that the Dockerfile is properly copied to the docker context dir before building the image
- make the build docker task to depend on the `assemble` task.

For example:
```groovy
Task dockerBuildTask = getDockerBuildTask("cli", project.projectDir)
dockerBuildTask.dependsOn(copyDocker)
assemble.dependsOn(dockerBuildTask)
```

If you need to add files in your image you need to copy them in `build/docker/bin` first. The need to happen after the `copyDocker` task.
The `copyDocker` task clean up the `build/docker` folder as a first step.

For example:
```groovy
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)
```

0 comments on commit 42b378f

Please sign in to comment.