From f0588227530714489fee3c6e0825f42c02345ec8 Mon Sep 17 00:00:00 2001 From: Lam Tran Date: Fri, 12 Aug 2022 12:01:39 +0200 Subject: [PATCH] #388 introduce multiarch images (#393) --- .github/workflows/cd.yml | 24 +++++++++++++++++++----- Dockerfile | 7 +++++++ README.md | 34 +++++++++++++++++----------------- build.gradle | 2 -- docs/CONTRIBUTING.md | 17 +++++++++++------ gradle-scripts/docker.gradle | 13 ------------- 6 files changed, 54 insertions(+), 43 deletions(-) create mode 100644 Dockerfile delete mode 100644 gradle-scripts/docker.gradle diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index f31cd26c..2f8931e7 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -19,8 +19,22 @@ jobs: with: java-version: 11 distribution: 'zulu' - - name: Build and push image to docker using gradle plugin - run: ./gradlew setLibraryVersion dockerPushImage -Dbuild.version=${{ steps.vars.outputs.tag }} --daemon - env: - DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} - DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + - name: Build java classes + run: ./gradlew setLibraryVersion assemble + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + - name: Build and push project sync + id: docker_build_extension + uses: docker/build-push-action@v3 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: commercetools/commercetools-project-sync:${{ steps.vars.outputs.tag }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..76f12c33 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM adoptopenjdk/openjdk11:jre +LABEL maintainer="PS Team Munich [ps-dev@commercetools.com]" +WORKDIR /app +COPY ./build/libs libs/ +COPY ./build/resources resources/ +COPY ./build/classes classes/ +ENTRYPOINT ["java", "-cp", "/app/resources:/app/classes:/app/libs/*", "com.commercetools.project.sync.SyncerApplication"] diff --git a/README.md b/README.md index dba4533d..af48b8fd 100644 --- a/README.md +++ b/README.md @@ -203,7 +203,7 @@ Example: ##### Download ```bash -docker pull commercetools/commercetools-project-sync:5.1.3 +docker pull commercetools/commercetools-project-sync:5.2.0 ``` ##### Run @@ -215,14 +215,14 @@ docker run \ -e TARGET_PROJECT_KEY=xxxx \ -e TARGET_CLIENT_ID=xxxx \ -e TARGET_CLIENT_SECRET=xxxx \ -commercetools/commercetools-project-sync:5.1.3 -s all +commercetools/commercetools-project-sync:5.2.0 -s all ``` ### Examples - To run the all sync modules from a source project to a target project ```bash - docker run commercetools/commercetools-project-sync:5.1.3 -s all + docker run commercetools/commercetools-project-sync:5.2.0 -s all ``` This will run the following sync modules in the given order: 1. `Type` Sync and `ProductType` Sync and `States` Sync and `TaxCategory` Sync and `CustomObject` Sync in parallel. @@ -232,68 +232,68 @@ commercetools/commercetools-project-sync:5.1.3 -s all - To run the type sync ```bash - docker run commercetools/commercetools-project-sync:5.1.3 -s types + docker run commercetools/commercetools-project-sync:5.2.0 -s types ``` - To run the productType sync ```bash - docker run commercetools/commercetools-project-sync:5.1.3 -s productTypes + docker run commercetools/commercetools-project-sync:5.2.0 -s productTypes ``` - To run the states sync ```bash - docker run commercetools/commercetools-project-sync:5.1.3 -s states + docker run commercetools/commercetools-project-sync:5.2.0 -s states ``` - To run the taxCategory sync ```bash - docker run commercetools/commercetools-project-sync:5.1.3 -s taxCategories + docker run commercetools/commercetools-project-sync:5.2.0 -s taxCategories ``` - To run the category sync ```bash - docker run commercetools/commercetools-project-sync:5.1.3 -s categories + docker run commercetools/commercetools-project-sync:5.2.0 -s categories ``` - To run the product sync ```bash - docker run commercetools/commercetools-project-sync:5.1.3 -s products + docker run commercetools/commercetools-project-sync:5.2.0 -s products ``` - To run the cartDiscount sync ```bash - docker run commercetools/commercetools-project-sync:5.1.3 -s cartDiscounts + docker run commercetools/commercetools-project-sync:5.2.0 -s cartDiscounts ``` - To run the inventoryEntry sync ```bash - docker run commercetools/commercetools-project-sync:5.1.3 -s inventoryEntries + docker run commercetools/commercetools-project-sync:5.2.0 -s inventoryEntries ``` - To run the customObject sync ```bash - docker run commercetools/commercetools-project-sync:5.1.3 -s customObjects + docker run commercetools/commercetools-project-sync:5.2.0 -s customObjects ``` - To run the customer sync ```bash - docker run commercetools/commercetools-project-sync:5.1.3 -s customers + docker run commercetools/commercetools-project-sync:5.2.0 -s customers ``` - To run the shoppingList sync ```bash - docker run commercetools/commercetools-project-sync:5.1.3 -s shoppingLists + docker run commercetools/commercetools-project-sync:5.2.0 -s shoppingLists ``` - To run both products and shoppingList sync ```bash - docker run commercetools/commercetools-project-sync:5.1.3 -s products shoppingLists + docker run commercetools/commercetools-project-sync:5.2.0 -s products shoppingLists ``` - To run type, productType and shoppingList sync ```bash - docker run commercetools/commercetools-project-sync:5.1.3 -s types productTypes shoppingLists + docker run commercetools/commercetools-project-sync:5.2.0 -s types productTypes shoppingLists ``` - To run all sync modules using a runner name ```bash - docker run commercetools/commercetools-project-sync:5.1.3 -s all -r myRunnerName + docker run commercetools/commercetools-project-sync:5.2.0 -s all -r myRunnerName ``` diff --git a/build.gradle b/build.gradle index f0e4cabf..3ba540b2 100644 --- a/build.gradle +++ b/build.gradle @@ -14,7 +14,6 @@ plugins { id "com.github.ben-manes.versions" version '0.42.0' id 'com.adarshr.test-logger' version '3.2.0' id 'com.diffplug.spotless' version '6.9.0' - id 'com.bmuschko.docker-java-application' version '7.4.0' id "com.github.spotbugs" version "5.0.9" } @@ -48,7 +47,6 @@ apply from: "$rootDir/gradle-scripts/pmd.gradle" apply from: "$rootDir/gradle-scripts/jacoco.gradle" apply from: "$rootDir/gradle-scripts/spotbugs.gradle" apply from: "$rootDir/gradle-scripts/shadow.gradle" -apply from: "$rootDir/gradle-scripts/docker.gradle" apply from: "$rootDir/gradle-scripts/execution-order.gradle" /** diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 5f834584..8ab65c3f 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -83,13 +83,18 @@ It is recommended to set it in your IDE auto formatting settings for this projec ./gradlew clean build ```` -### Build +### Build a docker image + +To build a docker image, you need to install docker. [Dockerfile](../Dockerfile) is provided in the root folder. +Before building a docker image, you need to compile java classes: +```bash +./gradlew setLibraryVersion assemble +``` +Then you can build the docker image with the following command: +```bash +docker buildx build --tag commercetools/commercetools-project-sync: . --load +``` - Gradle docker plugin is used to build and deploy the docker images. - To build the docker image locally, please run - ````bash -./gradlew dockerBuildImage -```` The docker image has been built and published to your desktop docker. Example: diff --git a/gradle-scripts/docker.gradle b/gradle-scripts/docker.gradle deleted file mode 100644 index c3d492a1..00000000 --- a/gradle-scripts/docker.gradle +++ /dev/null @@ -1,13 +0,0 @@ -docker { - javaApplication { - baseImage = 'adoptopenjdk/openjdk11:alpine-jre' - maintainer = 'PS Team Munich [ps-dev@commercetools.com]' - images = ['commercetools/commercetools-project-sync:' + version] - ports = [] - } - registryCredentials { - username = System.getenv('DOCKER_USERNAME') - password = System.getenv('DOCKER_PASSWORD') - } -} -