Skip to content

Commit

Permalink
DPS 3 - aarch64 binary (#291)
Browse files Browse the repository at this point in the history
* trying to create build modules

* try to create artifacts in a new mode

* setup arm64 builder

* adjustments

* it's owrking

* improvements

* new way to build aarch binary

* Looks like fixed arm build

* exporting native-image-source

* fixed

* adjustments

* new version

* new version

* force to not use cache

* adjusting copy

* unnecessary var

* setup qemu

* adjusting and praying

* release notes

* final adjustments

* bump version

* cleanup

* disabling latest for now

* deleting unused files

* add version to the gzip filename, zip without any dir

* Fixing command
  • Loading branch information
mageddo authored Feb 20, 2023
1 parent a1ed0f4 commit 8def710
Show file tree
Hide file tree
Showing 15 changed files with 185 additions and 87 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
**/node_modules
build

#*
#!build/*-runner
#!build/*-runner.jar
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/actions-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: CD

on:
push:
branches:
Expand All @@ -23,8 +24,11 @@ jobs:
with:
fetch-depth: '0'

- name: Configure Qemu
run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes

- name: Deploy
run: docker-compose -f docker-compose-deploy.yml up --force-recreate --exit-code-from deploy deploy
run: docker-compose -f docker-compose-deploy.yml up --build --force-recreate --exit-code-from deploy deploy
env:
# github token to deploy the binary
REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
25 changes: 25 additions & 0 deletions DRAFT.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,28 @@ java -cp './build/dns-proxy-server-3.0.0-alpha-runner.jar:../annotation-process
docker-compose -f docker-compose-tmp.yml up --build



## To build native image manually when using quarkus
Command copied from `./gradlew clean build -Dquarkus.package.type=native -i -x check`

```bash
$ cd build/dns-proxy-server-native-image-source-jar
$ native-image -J-Djava.util.logging.manager=org.jboss.logmanager.LogManager -J-Dsun.nio.ch.maxUpdateArraySize=100 \
-J-Dlogging.initial-configurator.min-level=500 -J-Dio.netty.leakDetection.level=DISABLED -J-Dio.netty.allocator.maxOrder=3 \
-J-Dvertx.logger-delegate-factory-class-name=io.quarkus.vertx.core.runtime.VertxLogDelegateFactory \
-J-Dvertx.disableDnsResolver=true -J-Duser.language=en -J-Duser.country=US -J-Dfile.encoding=UTF-8 \
--features=io.quarkus.runner.Feature,io.quarkus.runtime.graal.ResourcesFeature,io.quarkus.runtime.graal.DisableLoggingFeature \
-J--add-exports=java.security.jgss/sun.security.krb5=ALL-UNNAMED -J--add-opens=java.base/java.text=ALL-UNNAMED \
-J--add-opens=java.base/java.io=ALL-UNNAMED -J--add-opens=java.base/java.lang.invoke=ALL-UNNAMED \
-J--add-opens=java.base/java.util=ALL-UNNAMED -H:+CollectImageBuildStatistics \
-H:ImageBuildStatisticsFile=dns-proxy-server-timing-stats.json \
-H:BuildOutputJSONFile=dns-proxy-server-build-output-stats.json -H:+AllowFoldMethods -J-Djava.awt.headless=true \
--no-fallback --link-at-build-time -H:+ReportExceptionStackTraces -H:-AddAllCharsets --enable-url-protocols=http \
-H:NativeLinkerOption=-no-pie -H:-UseServiceLoaderFeature -H:+StackTrace \
-J--add-exports=org.graalvm.sdk/org.graalvm.nativeimage.impl=ALL-UNNAMED \
-J--add-exports=org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk=ALL-UNNAMED \
--exclude-config io\.netty\.netty-codec /META-INF/native-image/io\.netty/netty-codec/generated/handlers/reflect-config\.json \
--exclude-config io\.netty\.netty-handler /META-INF/native-image/io\.netty/netty-handler/generated/handlers/reflect-config\.json dns-proxy-server \
-jar dns-proxy-server.jar

```
11 changes: 1 addition & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
FROM docker.io/defreitas/tools_graalvm-22.3_java-19_debian-9:0.1.1 AS BUILDER
COPY ./ /app
WORKDIR /app
RUN ./gradlew clean build -Dquarkus.package.type=native -i &&\
cd build &&\
ls -lha &&\
mkdir -p artifacts &&\
mv $(ls -p ./ | grep -v / | grep dns-proxy-server) ./artifacts/

FROM debian:10-slim
COPY --from=BUILDER /app/build/artifacts/* /app/dns-proxy-server
COPY ./build/artifacts/linux-amd64/dns-proxy-server /app/dns-proxy-server
WORKDIR /app
LABEL dps.container=true
VOLUME ["/var/run/docker.sock", "/var/run/docker.sock"]
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.arm8x64 → Dockerfile.aarch64
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM arm64v8/debian:10-slim
ADD build/dns-proxy-server-linux-arm64-*.tgz /app/
COPY ./build/artifacts/linux-aarch64/dns-proxy-server /app/dns-proxy-server
WORKDIR /app
LABEL dps.container=true
VOLUME ["/var/run/docker.sock", "/var/run/docker.sock"]
Expand Down
6 changes: 0 additions & 6 deletions Dockerfile.arm7x86

This file was deleted.

5 changes: 0 additions & 5 deletions Dockerfile.arm7x86.build

This file was deleted.

29 changes: 29 additions & 0 deletions Dockerfile.builder.linux-aarch64
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM defreitas/tools_graalvm-22.3_java-17_debian-9_aarch64:0.1.3
WORKDIR /app/build
COPY ./build/artifacts/native-image-source/ /app/build

ENV JAVA_TOOL_OPTIONS='-Djdk.lang.Process.launchMechanism=fork'
RUN uname -m && ls -lha &&\
native-image -Djdk.lang.Process.launchMechanism=fork -J-Djdk.lang.Process.launchMechanism=fork -J-Djava.util.logging.manager=org.jboss.logmanager.LogManager -J-Dsun.nio.ch.maxUpdateArraySize=100 \
-J-Dlogging.initial-configurator.min-level=500 -J-Dio.netty.leakDetection.level=DISABLED -J-Dio.netty.allocator.maxOrder=3 \
-J-Dvertx.logger-delegate-factory-class-name=io.quarkus.vertx.core.runtime.VertxLogDelegateFactory \
-J-Dvertx.disableDnsResolver=true -J-Duser.language=en -J-Duser.country=US -J-Dfile.encoding=UTF-8 \
--features=io.quarkus.runner.Feature,io.quarkus.runtime.graal.ResourcesFeature,io.quarkus.runtime.graal.DisableLoggingFeature \
-J--add-exports=java.security.jgss/sun.security.krb5=ALL-UNNAMED -J--add-opens=java.base/java.text=ALL-UNNAMED \
-J--add-opens=java.base/java.io=ALL-UNNAMED -J--add-opens=java.base/java.lang.invoke=ALL-UNNAMED \
-J--add-opens=java.base/java.util=ALL-UNNAMED -H:+CollectImageBuildStatistics \
-H:ImageBuildStatisticsFile=dns-proxy-server-timing-stats.json \
-H:BuildOutputJSONFile=dns-proxy-server-build-output-stats.json -H:+AllowFoldMethods -J-Djava.awt.headless=true \
--no-fallback --link-at-build-time -H:+ReportExceptionStackTraces -H:-AddAllCharsets --enable-url-protocols=http \
-H:NativeLinkerOption=-no-pie -H:-UseServiceLoaderFeature -H:+StackTrace \
-J--add-exports=org.graalvm.sdk/org.graalvm.nativeimage.impl=ALL-UNNAMED \
-J--add-exports=org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk=ALL-UNNAMED \
--exclude-config io\.netty\.netty-codec /META-INF/native-image/io\.netty/netty-codec/generated/handlers/reflect-config\.json \
--exclude-config io\.netty\.netty-handler /META-INF/native-image/io\.netty/netty-handler/generated/handlers/reflect-config\.json dns-proxy-server \
-jar dns-proxy-server.jar

RUN ls -lha &&\
mkdir -p ./artifacts/linux-aarch64 &&\
mv ./dns-proxy-server ./artifacts/linux-aarch64/

ENTRYPOINT cat
10 changes: 10 additions & 0 deletions Dockerfile.builder.linux-amd64
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM docker.io/defreitas/tools_graalvm-22.3_java-19_debian-9:0.1.1 AS BUILDER
COPY ./ /app
WORKDIR /app
RUN ./gradlew clean build -Dquarkus.package.type=native -i &&\
./gradlew build -Dquarkus.package.type=uber-jar -i -x check &&\
ls -lha ./build &&\
mkdir -p ./build/artifacts/linux-amd64 && mv ./build/dns-proxy-server ./build/artifacts/linux-amd64/ &&\
mkdir -p ./build/artifacts/jre && mv ./build/dns-proxy-server.jar ./build/artifacts/jre/ &&\
mv ./build/dns-proxy-server-native-image-source-jar ./build/artifacts/native-image-source
ENTRYPOINT cat
5 changes: 5 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### 3.0.4-beta
* Generating new distributions binaries
* aarch64 aside docker image
* uber jar, target jvm = 17 for now

### 3.0.2-beta
* Fixed home page was pointing to wrong place

Expand Down
130 changes: 88 additions & 42 deletions builder.bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set -e

REPO_DIR=`pwd`
APP_VERSION=$(cat gradle.properties | grep -oP 'version=\K(.+)')
export VERSION=${APP_VERSION}

echo "> builder.bash version=${APP_VERSION}, path=${REPO_DIR}"

Expand All @@ -24,63 +25,108 @@ copyFileFromService(){
from=$2
to=$3

docker-compose up --no-start --build --force-recreate $serviceName 1>&2
id=$(docker ps -a | grep $serviceName | awk '{print $1}')
id=$(docker-compose up --no-start --build --force-recreate $serviceName 2>&1 | grep Container | awk '{print $2}' | head -1)
echo "> copy from service=${serviceName}, id=${id}, from=${from}, to=${to}"
docker cp "$id:$from" "$to"
}

validateRelease(){
echo "> validate release, version=${APP_VERSION}, git=$(git rev-parse $APP_VERSION 2>/dev/null)"
if git rev-parse "$APP_VERSION^{}" >/dev/null 2>&1; then
echo "> Tag already exists $APP_VERSION"
exit 3
fi
}

case $1 in

copy )
copyFileFromService build-frontend /static ./src/main/resources/META-INF/resources/static
;;

validate-release )
echo "> validate release, version=${APP_VERSION}, git=$(git rev-parse $APP_VERSION 2>/dev/null)"
if git rev-parse "$APP_VERSION^{}" >/dev/null 2>&1; then
echo "> Tag already exists $APP_VERSION"
exit 3
fi
validateRelease
;;

build-frontend )

echo "> Building frontend files..."
docker-compose build --no-cache --progress=plain build-frontend
rm -rf ./src/main/resources/META-INF/resources/static
copyFileFromService build-frontend /static ./src/main/resources/META-INF/resources/static

echo "> Build, test and generate the binaries"
mkdir -p "${REPO_DIR}/build"

;;

build-backend )

OS=linux
ARCH=$2
BUILD_SERVICE_NAME="build-${OS}-${ARCH}"
IMAGE_SERVICE_NAME="image-${OS}-${ARCH}"
ARTIFACTS_DIR="${REPO_DIR}/build/artifacts"

echo "> building backend to: os=${OS}, arch=${ARCH}"

mkdir -p ${ARTIFACTS_DIR}

docker-compose build --no-cache --progress=plain ${BUILD_SERVICE_NAME}

copyFileFromService ${BUILD_SERVICE_NAME} /app/build/artifacts /tmp/
mv -v /tmp/artifacts/* ${ARTIFACTS_DIR}

docker-compose build --no-cache --progress=plain "${IMAGE_SERVICE_NAME}"

;;

compress-upload-artifacts )
echo "> compress the files ..."
./builder.bash validate-release || exit 0

ARTIFACTS_DIR="${REPO_DIR}/build/artifacts"
COMPRESSED_ARTIFACTS_DIR="${REPO_DIR}/build/compressed-artifacts"

mkdir -p ${COMPRESSED_ARTIFACTS_DIR}
cd ${ARTIFACTS_DIR}

ls ${ARTIFACTS_DIR} | grep -v "native-image-source" |\
while read -r artPath ; do
tgz="${COMPRESSED_ARTIFACTS_DIR}/dns-proxy-server-${artPath}-${APP_VERSION}.tgz"
tar -czvf ${tgz} -C ${artPath} .
echo "> compressed ${artPath} to ${tgz} ..."
done

echo "> Uploading the release artifacts"
cd $REPO_DIR
DESC=$(cat RELEASE-NOTES.md | awk 'BEGIN {RS="|"} {print substr($0, 0, index(substr($0, 3), "###"))}' | sed ':a;N;$!ba;s/\n/\\r\\n/g')
github-cli release mageddo dns-proxy-server $APP_VERSION $CURRENT_BRANCH "${DESC}" ${COMPRESSED_ARTIFACTS_DIR}/*.tgz

;;

docker-push )
echo "> Push docker images to docker hub"
# docker tag defreitas/dns-proxy-server:${APP_VERSION} defreitas/dns-proxy-server:latest &&\
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin &&\
docker-compose push image-linux-amd64 image-linux-aarch64
;;

deploy )

echo "> Deploy started , current branch=$CURRENT_BRANCH"
rm -vrf build
ls -lha

./builder.bash validate-release || exit 0

if [ "$CURRENT_BRANCH" != "master" ]; then
echo "> refusing to go ahead outside the master branch"
exit 8
fi
./builder.bash build-frontend
./builder.bash build-backend amd64 #also builds the jar
./builder.bash build-backend aarch64

echo "> Building frontend files..."
docker-compose build --progress=plain build-frontend
rm -rf ./src/main/resources/META-INF/resources/static
copyFileFromService build-frontend /static ./src/main/resources/META-INF/resources/static

echo "> Build, test and generate the binaries"
mkdir -p "${REPO_DIR}/build"

OS=linux
ARCH=amd64
SERVICE_NAME="build-${OS}-${ARCH}"
BIN_FILE="${REPO_DIR}/build/dns-proxy-server-${OS}-${ARCH}-${APP_VERSION}"
TAR_FILE=${BIN_FILE}.tgz

VERSION=${APP_VERSION} docker-compose build --progress=plain ${SERVICE_NAME}
copyFileFromService ${SERVICE_NAME} /app/dns-proxy-server ${BIN_FILE}
cd $REPO_DIR/build/
tar --exclude=*.tgz -czf $TAR_FILE $(basename ${BIN_FILE})

echo "> Uploading the release artifacts"
cd $REPO_DIR
DESC=$(cat RELEASE-NOTES.md | awk 'BEGIN {RS="|"} {print substr($0, 0, index(substr($0, 3), "###"))}' | sed ':a;N;$!ba;s/\n/\\r\\n/g')
github-cli release mageddo dns-proxy-server $APP_VERSION $CURRENT_BRANCH "${DESC}" $REPO_DIR/build/*.tgz

echo "> Push docker images to docker hub"
# docker-compose build prod-build-image-dps prod-build-image-dps-arm7x86 prod-build-image-dps-arm8x64 &&\
# docker tag defreitas/dns-proxy-server:${APP_VERSION} defreitas/dns-proxy-server:latest &&\
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin &&\
VERSION=${APP_VERSION} docker-compose push build-linux-amd64
# docker-compose push prod-build-image-dps prod-build-image-dps-arm7x86 prod-build-image-dps-arm8x64 &&
# docker push defreitas/dns-proxy-server:latest
./builder.bash compress-upload-artifacts

./builder.bash docker-push
;;

deploy-docs )
Expand Down
7 changes: 0 additions & 7 deletions docker-compose-alpha.yml

This file was deleted.

31 changes: 18 additions & 13 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '2.3'
version: '3'
services:

# tag:build
Expand All @@ -9,25 +9,30 @@ services:
image: defreitas/dns-proxy-server-build-frontend:${VERSION:-snapshot}

build-linux-amd64:
image: defreitas/dns-proxy-server:${VERSION:-snapshot}
image: defreitas/dns-proxy-server-build:${VERSION:-snapshot}-amd64
build:
context: .
dockerfile: Dockerfile
dockerfile: Dockerfile.builder.linux-amd64

# end:build

# tag:development
build-linux-aarch64:
image: defreitas/dns-proxy-server-build:${VERSION:-snapshot}-aarch64
build:
context: .
dockerfile: Dockerfile.builder.linux-aarch64
platform: linux/arm64/v8

# end:development
# end:build

prod-build-image-dps-arm7x86:
# tag:image
image-linux-amd64:
image: defreitas/dns-proxy-server:${VERSION:-snapshot}
build:
context: .
dockerfile: Dockerfile.arm7x86
image: defreitas/dns-proxy-server:${VERSION:-snapshot}-arm7x86
dockerfile: Dockerfile

prod-build-image-dps-arm8x64:
image-linux-aarch64:
image: defreitas/dns-proxy-server:${VERSION:-snapshot}-aarch64
build:
context: .
dockerfile: Dockerfile.arm8x64
image: defreitas/dns-proxy-server:${VERSION:-snapshot}-arm8x64
dockerfile: Dockerfile.aarch64
# end:image
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=3.0.2-beta
version=3.0.4-beta
quarkusPluginId=io.quarkus
quarkusPluginVersion=2.16.0.Final
quarkusPlatformGroupId=io.quarkus.platform
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ quarkus.log.category."com.mageddo".level=DEBUG
# quarkus-core-deployment-2.16.0.Final.jar!/META-INF/quarkus-javadoc.properties
#quarkus.package.runner-suffix=

quarkus.package.output-name=dns-proxy-server
quarkus.package.add-runner-suffix=false
#quarkus.package.output-directory=artifacts

0 comments on commit 8def710

Please sign in to comment.