Skip to content

Commit

Permalink
#285 AMD64 Static Binary and Docker Image (#493)
Browse files Browse the repository at this point in the history
* setup static binary for linux amd64

* generating release on pullrequest

* [Gradle Release Plugin] - new version commit:  '3.20.1-snapshot'.

* release notes

* [Gradle Release Plugin] - new version commit:  '3.21.0-snapshot'.

* setup docker image

* fixing path

* adjusting amd64 static building

* adjusting amd64 static building

* adjusting amd64 static building

* adjusting amd64 static building

* adjusting amd64 static building

* upgrading running docker images

* create tmp dir when it not exists

* upgrading docker image

* release notes

* [Gradle Release Plugin] - new version commit:  '3.21.1-snapshot'.

* reverting feature

* release notes

* release notes

* release notes

* adjusting ci cd
  • Loading branch information
mageddo authored Jun 24, 2024
1 parent 099b1c4 commit 7147f5e
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 5 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/actions-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches:
- master


permissions:
contents: write

Expand Down Expand Up @@ -66,6 +67,44 @@ jobs:
files: |
./build/compressed-artifacts/*
linux_amd64_static_release:
runs-on: ubuntu-latest
needs: primary_release
env:
APP_VERSION: ${{ needs.primary_release.outputs.APP_VERSION }}
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Check app version
run: echo "$APP_VERSION"

- uses: actions/download-artifact@v3
with:
name: native-image-source
path: ./build/artifacts/native-image-source/

- name: Linux Amd64 static Release
run: |
echo "app version=$APP_VERSION" &&\
tree -h ./build/ &&\
docker-compose -f docker-compose-deploy.yml run deploy bash -c '
/bin/builder.bash deploy-amd64-static &&\
echo "> Copying files to the host" &&\
cp -rv /app/build/compressed-artifacts /host/build/ &&\
echo "Linux amd64 static is done!"
' &&\
tree -h ./build/
# Release details will be provided by primary-release
- name: Github release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ env.APP_VERSION }}
append_body: true
body: ''
files: |
./build/compressed-artifacts/*
linux_arm_release:
runs-on: ubuntu-latest
needs: primary_release
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM debian:10-slim
FROM debian:12-slim
COPY ./build/artifacts/linux-amd64/dns-proxy-server /app/dns-proxy-server
WORKDIR /app
LABEL dps.container=true
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.aarch64
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM arm64v8/debian:10-slim
FROM arm64v8/debian:12-slim
COPY ./build/artifacts/linux-aarch64/dns-proxy-server /app/dns-proxy-server
WORKDIR /app
LABEL dps.container=true
Expand Down
8 changes: 8 additions & 0 deletions Dockerfile.amd64-static
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM scratch
COPY ./build/artifacts/linux-amd64-static/dns-proxy-server /app/dns-proxy-server
WORKDIR /app
LABEL dps.container=true
ENV DPS_CONTAINER=1
VOLUME ["/var/run/docker.sock", "/var/run/docker.sock"]
ENTRYPOINT ["/app/dns-proxy-server"]
CMD ["-D", "java.io.tmpdir=/app"]
43 changes: 43 additions & 0 deletions Dockerfile.builder.linux-amd64-static
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
FROM debian:11

RUN apt-get update -y &&\
apt-get install --force-yes -y build-essential libz-dev zlib1g-dev curl

ARG RESULT_LIB="/musl"

RUN mkdir ${RESULT_LIB} && \
curl -L -o musl.tar.gz https://more.musl.cc/10.2.1/x86_64-linux-musl/x86_64-linux-musl-native.tgz && \
tar -xvzf musl.tar.gz -C musl --strip-components 1 && \
cp /usr/lib/gcc/x86_64-linux-gnu/10/libstdc++.a ${RESULT_LIB}/lib/

ENV CC=/musl/bin/gcc

RUN curl -L -o zlib.tar.gz https://www.zlib.net/fossils/zlib-1.2.11.tar.gz && \
mkdir zlib && tar -xvzf zlib.tar.gz -C zlib --strip-components 1 && \
cd zlib && ./configure --static --prefix=/musl && \
make && make install && \
cd / && rm -rf /zlib && rm -f /zlib.tar.gz

ENV PATH="$PATH:/musl/bin"
ENV GRAALVM_URL='https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-21.0.2/graalvm-community-jdk-21.0.2_linux-x64_bin.tar.gz'

RUN mkdir /graalvm &&\
curl -L $GRAALVM_URL > /tmp/graalvm.tgz &&\
tar --strip 1 -zxvf /tmp/graalvm.tgz -C /graalvm &&\
rm -r /tmp/* || true

ENV JAVA_HOME=/graalvm
ENV PATH="${PATH}:$JAVA_HOME/bin"
RUN uname -a && whoami && $JAVA_HOME/bin/java -version

WORKDIR /app/build
COPY ./build/artifacts/native-image-source/ /app/build

RUN ls -lha &&\
native-image --static --libc=musl -jar dns-proxy-server.jar dns-proxy-server

RUN ls -lhS &&\
mkdir -p ./artifacts/linux-amd64-static &&\
mv ./dns-proxy-server ./artifacts/linux-amd64-static/

ENTRYPOINT cat
4 changes: 4 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.21.1
* #435: Upgrading docker run images due glibc
* #285: Linux AMD64 static binary

## 3.20.0
* #435: GraalVM Upgrade to 21 LTS

Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ graalvmNative {
verbose = true
fallback = false
buildArgs.add('-J-Xmx5G')

}
}
}
Expand Down
21 changes: 20 additions & 1 deletion builder.bash
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,19 @@ case $1 in
;;

docker-push-arm )
echo "> Push docker images to docker hub"
echo "> Push docker arm image to docker hub"
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin &&\
docker-compose push image-linux-aarch64
echo "Push done"
;;

docker-push-amd64-static )
echo "> Push docker amd64 static image to docker hub"
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin &&\
docker-compose push image-linux-amd64-static
echo "Push done"
;;

deploy )

echo "> Deploy started , current branch=$CURRENT_BRANCH"
Expand All @@ -136,6 +143,18 @@ case $1 in
echo "> deploy done"
;;

deploy-amd64-static )

echo "> Amd64 static deploy started , current branch=$CURRENT_BRANCH"
ls -lhS build/*

./builder.bash build-backend amd64-static
./builder.bash compress-artifacts
./builder.bash docker-push-amd64-static

echo "> Amd64 Static deploy done"
;;

deploy-arm )

echo "> Arm deploy started , current branch=$CURRENT_BRANCH"
Expand Down
12 changes: 12 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ services:
context: .
dockerfile: Dockerfile.builder.linux-amd64

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

build-linux-aarch64:
image: defreitas/dns-proxy-server-build:${VERSION:-snapshot}-aarch64
build:
Expand All @@ -30,6 +36,12 @@ services:
context: .
dockerfile: Dockerfile

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

image-linux-aarch64:
image: defreitas/dns-proxy-server:${VERSION:-snapshot}-aarch64
build:
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=3.20.0-snapshot
version=3.21.1-snapshot
2 changes: 1 addition & 1 deletion src/test/java/com/mageddo/dnsproxyserver/AppCompTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void mustExitWhenHelpCmd() {


@Test
void mustExitWhenVerrsionCmd() {
void mustExitWhenVersionCmd() {
// arrange
final var args = new String[]{"--version"};
this.app = spy(new App(args));
Expand Down

0 comments on commit 7147f5e

Please sign in to comment.