From 0c48a83bb5751abf7c8c0ff188bfdc2130631e78 Mon Sep 17 00:00:00 2001 From: Marius Scurtescu Date: Fri, 7 Jun 2024 00:50:15 +0000 Subject: [PATCH] create docker image based on release binaries --- DOCKER-README.md | 4 +-- Dockerfile.release | 55 +++++++++++++++++++++++++++++++++ Dockerfile => Dockerfile.source | 0 Taskfile.yaml | 41 +++++++++++++++++++----- docker/docker-compose.yml | 9 +----- signers/Taskfile.yaml | 11 ++++--- 6 files changed, 97 insertions(+), 23 deletions(-) create mode 100644 Dockerfile.release rename Dockerfile => Dockerfile.source (100%) diff --git a/DOCKER-README.md b/DOCKER-README.md index af2159d..457ff76 100644 --- a/DOCKER-README.md +++ b/DOCKER-README.md @@ -6,9 +6,9 @@ The only requirements are `git` (to checkout the repository) and docker (to buil Golang does not have to be installed, the docker image build process uses a build stage that provides the correct Go environment and compiles the node down to one command. -In the repository root folder, where the [Dockerfile](Dockerfile) file is, build the docker image: +In the repository root folder, where the [Dockerfile.source](Dockerfile.source) file is, build the docker image: ```shell -docker build --build-arg GIT_COMMIT=$(git log -1 --format=%h) -t quilibrium -t quilibrium:1.4.16 . +docker build -f Dockerfile.source --build-arg GIT_COMMIT=$(git log -1 --format=%h) -t quilibrium -t quilibrium:1.4.16 . ``` Use latest version instead of `1.4.16`. diff --git a/Dockerfile.release b/Dockerfile.release new file mode 100644 index 0000000..f6f3b2e --- /dev/null +++ b/Dockerfile.release @@ -0,0 +1,55 @@ +FROM golang:1.20.14-alpine3.19 as build + +ARG NODE_VERSION +ARG MAX_KEY_ID + +ENV GOEXPERIMENT=arenas + +WORKDIR /opt/ceremonyclient + +COPY . . + +RUN cp "node/node-${NODE_VERSION}-linux-amd64" "node/node" +RUN cp "node/node-${NODE_VERSION}-linux-amd64.dgst" "node/node.dgst" +RUN for i in $(seq 1 ${MAX_KEY_ID}); do \ + if [ -f node/node-${NODE_VERSION}-linux-amd64.dgst.sig.${i} ]; then \ + cp "node/node-${NODE_VERSION}-linux-amd64.dgst.sig.${i}" "node/node.dgst.sig.${i}"; \ + fi \ + done + +WORKDIR /opt/ceremonyclient/client + +RUN go build -o qclient ./main.go + +RUN go install github.com/fullstorydev/grpcurl/cmd/grpcurl@v1.9.1 + +FROM alpine:3.19 + +ARG NODE_VERSION +ARG GIT_REPO +ARG GIT_BRANCH +ARG GIT_COMMIT + +ENV GOEXPERIMENT=arenas + +LABEL org.opencontainers.image.title="Quilibrium Network Node" +LABEL org.opencontainers.image.description="Quilibrium is a decentralized alternative to platform as a service providers." +LABEL org.opencontainers.image.version=$NODE_VERSION +LABEL org.opencontainers.image.vendor=Quilibrium +LABEL org.opencontainers.image.url=https://quilibrium.com/ +LABEL org.opencontainers.image.documentation=https://quilibrium.com/docs +LABEL org.opencontainers.image.source=$GIT_REPO +LABEL org.opencontainers.image.ref.name=$GIT_BRANCH +LABEL org.opencontainers.image.revision=$GIT_COMMIT + +COPY --from=build /opt/ceremonyclient/node/node /usr/local/bin +COPY --from=build /opt/ceremonyclient/node/node.dgst /usr/local/bin +COPY --from=build /opt/ceremonyclient/node/node.dgst.sig.* /usr/local/bin + +COPY --from=build /opt/ceremonyclient/client/qclient /usr/local/bin + +COPY --from=build /go/bin/grpcurl /usr/local/bin + +WORKDIR /root + +ENTRYPOINT ["node"] diff --git a/Dockerfile b/Dockerfile.source similarity index 100% rename from Dockerfile rename to Dockerfile.source diff --git a/Taskfile.yaml b/Taskfile.yaml index a2de09e..8e1b843 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -5,6 +5,9 @@ version: '3' dotenv: - '.env' +env: + DOCKER_BUILDKIT: '1' + vars: VERSION: sh: cat node/config/version.go | grep -A 1 "func GetVersion() \[\]byte {" | grep -Eo '0x[0-9a-fA-F]+' | xargs printf "%d.%d.%d" @@ -14,6 +17,7 @@ vars: sh: git rev-parse --abbrev-ref HEAD GIT_COMMIT: sh: git log -1 --format=%h + MAX_KEY_ID: 17 tasks: status: @@ -24,33 +28,54 @@ tasks: - echo -n "Repo :" && echo " {{.GIT_REPO}}" - echo -n "Branch :" && echo " {{.GIT_BRANCH}}" - echo -n "Commit :" && echo " {{.GIT_COMMIT}}" + - echo -n "Max Key ID:" && echo " {{.MAX_KEY_ID}}" silent: true - build: - desc: Build the Quilibrium docker image, unless it is already built. + build:source: + desc: Build the Quilibrium docker image from source. cmds: - | docker build \ + -f Dockerfile.source \ --build-arg NODE_VERSION={{.VERSION}} \ --build-arg GIT_REPO={{.GIT_REPO}} \ --build-arg GIT_BRANCH={{.GIT_BRANCH}} \ --build-arg GIT_COMMIT={{.GIT_COMMIT}} \ - -t ${QUILIBRIUM_IMAGE_NAME:-quilibrium}:{{.VERSION}} \ - -t ${QUILIBRIUM_IMAGE_NAME:-quilibrium}:latest \ + -t ${QUILIBRIUM_IMAGE_NAME:-quilibrium}:{{.VERSION}}-source \ + -t ${QUILIBRIUM_IMAGE_NAME:-quilibrium}:source \ . status: - | docker image inspect \ - ${QUILIBRIUM_IMAGE_NAME:-quilibrium}:{{.VERSION}} \ + ${QUILIBRIUM_IMAGE_NAME:-quilibrium}:{{.VERSION}}-source \ >/dev/null 2>/dev/null - github:login: - desc: Login to GitHub container registry. + build:release: + desc: Build the Quilibrium docker image from release binaries. + aliases: + - build cmds: - - echo $GITHUB_TOKEN | docker login ghcr.io -u $GITHUB_USERNAME --password-stdin + - | + docker build \ + -f Dockerfile.release \ + --build-arg NODE_VERSION={{.VERSION}} \ + --build-arg GIT_REPO={{.GIT_REPO}} \ + --build-arg GIT_BRANCH={{.GIT_BRANCH}} \ + --build-arg GIT_COMMIT={{.GIT_COMMIT}} \ + --build-arg MAX_KEY_ID={{.MAX_KEY_ID}} \ + -t ${QUILIBRIUM_IMAGE_NAME:-quilibrium}:{{.VERSION}}-release \ + -t ${QUILIBRIUM_IMAGE_NAME:-quilibrium}:release \ + . + status: + - | + docker image inspect \ + ${QUILIBRIUM_IMAGE_NAME:-quilibrium}:{{.VERSION}}-release \ + >/dev/null 2>/dev/null docker:login: desc: Login to Docker hub + aliases: + - login cmds: - echo $DOCKER_TOKEN | docker login -u $DOCKER_USERNAME --password-stdin diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 1d93017..816b238 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -7,13 +7,6 @@ services: node: image: ${QUILIBRIUM_IMAGE_NAME:-quilibrium} restart: unless-stopped - deploy: - resources: - limits: - memory: '32G' - reservations: - cpus: '12' - memory: '16G' environment: - DEFAULT_LISTEN_GRPC_MULTIADDR=/ip4/0.0.0.0/tcp/8337 - DEFAULT_LISTEN_REST_MULTIADDR=/ip4/0.0.0.0/tcp/8338 @@ -27,7 +20,7 @@ services: interval: 30s timeout: 5s retries: 3 - start_period: 1m + start_period: 15m volumes: - ./.config:/root/.config logging: diff --git a/signers/Taskfile.yaml b/signers/Taskfile.yaml index a5d4c3f..4e73bce 100644 --- a/signers/Taskfile.yaml +++ b/signers/Taskfile.yaml @@ -11,7 +11,7 @@ env: vars: VERSION: sh: cat ../node/config/version.go | grep -A 1 "func GetVersion() \[\]byte {" | grep -Eo '0x[0-9a-fA-F]+' | xargs printf "%d.%d.%d" - MAX_KEY_ID: 15 + MAX_KEY_ID: 17 QUILIBRIUM_SIGNERS_IMAGE_NAME: 'quilibrium-signers' USER_NAME: sh: whoami @@ -23,10 +23,11 @@ tasks: status: desc: Display configuration info. cmds: - - echo -n "Version :" && echo " {{.VERSION}}" - - echo -n "Priv Key Path :" && echo " {{.SIGNING_KEY_PATH}}" - - echo -n "Pub Key Path :" && echo " {{.SIGNING_PUB_KEY_PATH}}" - - echo -n "Key ID :" && echo " {{.SIGNING_KEY_ID}}" + - echo -n "Version :" && echo " {{.VERSION}}" + - echo -n "Priv Key Path:" && echo " {{.SIGNING_KEY_PATH}}" + - echo -n "Pub Key Path:" && echo " {{.SIGNING_PUB_KEY_PATH}}" + - echo -n "Key ID :" && echo " {{.SIGNING_KEY_ID}}" + - echo -n "Max Key ID :" && echo " {{.MAX_KEY_ID}}" silent: true hex: