Skip to content

Commit

Permalink
W 16954625.build arm64 image (#1013)
Browse files Browse the repository at this point in the history
* W-16954625: Build arm64 docker image
  • Loading branch information
peterzxu-crm authored Oct 15, 2024
1 parent 4985644 commit 6fb43e2
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- name: Publish Docker container
if: ${{ !contains(github.ref, 'dependabot') }}
# run: ./gradlew -PdockerRepo=docker.pkg.github.com/${{ github.repository }}/ -x test publish --info
run: ./gradlew -PdockerRepo=salesforce/ -x test publish --info
run: docker buildx create --driver docker-container --driver-opt='image=moby/buildkit:buildx-stable-1' --name buildbase --platform linux/arm64,linux/amd64 && ./gradlew -PdockerRepo=salesforce/ -x test publish --info
# - name: scan docker image
# if: ${{ !contains(github.ref, 'dependabot') }}
# uses: azure/container-scan@v0
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ jobs:
- name: Release with Gradle
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./gradlew -PdockerRepo=salesforce/ clean build -Prelease.useAutomaticVersion=true -x test :carbonj.service:release --info --stacktrace
run: docker buildx create --driver docker-container --driver-opt='image=moby/buildkit:buildx-stable-1' --name buildbase --platform linux/arm64,linux/amd64 && ./gradlew -PdockerRepo=salesforce/ clean build -Prelease.useAutomaticVersion=true -x test :carbonj.service:release --info --stacktrace
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ buildscript {
}

plugins {
id 'com.palantir.docker' version "${palantirDocker}"
id "com.github.jk1.dependency-license-report" version "${dependencyLicenseReport}"
id "com.github.hierynomus.license" version "${hierynomusLicense}"
id "org.sonarqube" version "${sonarqube}"
Expand Down
18 changes: 9 additions & 9 deletions carbonj.service/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#

FROM registry.access.redhat.com/ubi9/ubi:9.4-1214.1726694543
ARG DEPENDENCY=build/docker/dependency
ARG DEPENDENCY=build/dependency
ARG VERSION=latest

# install dependencies
Expand All @@ -18,15 +18,15 @@ RUN yum update -y && \
yum install -y gcc-c++ gcc make libtool automake autoconf make python3-devel && \
rpm --import http://repos.azulsystems.com/RPM-GPG-KEY-azulsystems && \
yum install -y https://cdn.azul.com/zulu/bin/zulu-repo-1.0.0-1.noarch.rpm && \
yum install -y https://mirror.stream.centos.org/9-stream/AppStream/x86_64/os/Packages/pcp-conf-6.2.1-1.el9.x86_64.rpm && \
yum install -y https://mirror.stream.centos.org/9-stream/AppStream/x86_64/os/Packages/pcp-libs-6.2.1-1.el9.x86_64.rpm && \
yum install -y https://mirror.stream.centos.org/9-stream/AppStream/$(uname -m)/os/Packages/pcp-conf-6.2.1-1.el9.$(uname -m).rpm && \
yum install -y https://mirror.stream.centos.org/9-stream/AppStream/$(uname -m)/os/Packages/pcp-libs-6.2.1-1.el9.$(uname -m).rpm && \
#
# If sysstat version is updated, confirm iolog.sh execution and update associated version check in entrypoint.sh
#
yum install -y https://mirror.stream.centos.org/9-stream/AppStream/x86_64/os/Packages/sysstat-12.5.4-7.el9.x86_64.rpm && \
yum install -y https://repo.almalinux.org/almalinux/9/extras/x86_64/os/Packages/epel-release-9-5.el9.noarch.rpm && \
yum install -y https://dl.fedoraproject.org/pub/epel/9/Everything/x86_64/Packages/p/perl-URI-Encode-1.1.1-17.el9.noarch.rpm && \
yum install -y https://rpmfind.net/linux/centos-stream/9-stream/BaseOS/x86_64/os/Packages/snappy-1.1.8-8.el9.x86_64.rpm && \
yum install -y https://mirror.stream.centos.org/9-stream/AppStream/$(uname -m)/os/Packages/sysstat-12.5.4-7.el9.$(uname -m).rpm && \
yum install -y https://repo.almalinux.org/almalinux/9/extras/$(uname -m)/os/Packages/epel-release-9-5.el9.noarch.rpm && \
yum install -y https://dl.fedoraproject.org/pub/epel/9/Everything/$(uname -m)/Packages/p/perl-URI-Encode-1.1.1-17.el9.noarch.rpm && \
yum install -y https://rpmfind.net/linux/centos-stream/9-stream/BaseOS/$(uname -m)/os/Packages/snappy-1.1.8-8.el9.$(uname -m).rpm && \
yum update -y && \
yum install -y zulu17-jdk python3 perl-Data-Dumper && \
yum clean all && \
Expand All @@ -38,8 +38,8 @@ RUN yum update -y && \
chkconfig crond on && \
systemctl enable crond.service && \
mkdir -p /app/bin/ && \
wget https://github.com/krallin/tini/releases/download/v0.19.0/tini && \
mv tini /sbin/tini && \
export ARCH=amd64 && if [ "$(uname -m)" = "aarch64" ]; then export ARCH=arm64; fi && \
wget https://github.com/krallin/tini/releases/download/v0.19.0/tini-${ARCH} -O /sbin/tini && \
chmod +x /sbin/tini

# add java code
Expand Down
34 changes: 23 additions & 11 deletions carbonj.service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'com.palantir.docker'
apply plugin: 'org.sonarqube'
apply plugin: 'maven-publish'
apply plugin: 'maven-publish-auth'
Expand Down Expand Up @@ -74,7 +73,6 @@ ext {
}
}


repositories {
mavenLocal()
mavenCentral()
Expand All @@ -89,14 +87,28 @@ task unpack(type: Copy) {
into("build/dependency")
}

docker {
print "name of the docker image is ${dockerRepo}${project.dockerGroup}:${project.version}"
name "${dockerRepo}${project.dockerGroup}:${project.version}"
tag 'docker', "${dockerRepo}${project.dockerGroup}:${project.version}"
files tasks.unpack.outputs, "src/main/docker/files"
copySpec.into("dependency")
buildArgs(['DEPENDENCY': "dependency", 'VERSION': "${project.version}"])
noCache true
task copyDockerFiles(type: Copy) {
from 'src/main/docker/files'
into 'build/dependency'
}

tasks.register('docker', Exec) {
dependsOn unpack, copyDockerFiles
def command = getDockerBuildCmd("${dockerRepo}${project.dockerGroup}:${project.version}", "${project.version}")
doFirst {
logger.lifecycle("${command.join(' ')}")
}
commandLine 'bash', '-c', command.join(' ')
}

static def getDockerBuildCmd(String name, version) {
def buildCommandLine = ['docker', 'buildx', 'build', '--platform', 'linux/amd64,linux/arm64', '--builder', 'buildbase', '--push']
// When build docker image on Mac, pick up the right command for either Intel chips or Mac Silicon and comment out the above command
// def buildCommandLine = ['docker', 'build', '--platform', 'linux/amd64', '--builder', 'buildbase', '--load']
// def buildCommandLine = ['docker', 'build', '--platform', 'linux/arm64', '--builder', 'buildbase', '--load']
buildCommandLine.addAll('--build-arg', "VERSION=${version}")
buildCommandLine.addAll('-t', name, '.')
return buildCommandLine
}

configurations {
Expand Down Expand Up @@ -143,7 +155,7 @@ task rpm(type: Rpm) {

// for release automatically push released docker and mvn image to repo
afterReleaseBuild.dependsOn publish
publish.dependsOn dockerPush
publish.dependsOn docker
publish.dependsOn build

publishing {
Expand Down
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ junit=5.11.0
gradleRelease=3.0.2
ospackage=11.10.0
mavenPublish=2.0.1
palantirDocker=0.36.0
dependencyLicenseReport=2.9
hierynomusLicense=0.16.1
sonarqube=5.1.0.4882

0 comments on commit 6fb43e2

Please sign in to comment.