Skip to content

Commit

Permalink
deploy: generalize and fix building aisnode image
Browse files Browse the repository at this point in the history
Signed-off-by: Janusz Marcinkiewicz <[email protected]>
  • Loading branch information
VirrageS committed Jul 3, 2024
1 parent 733688e commit 434a89c
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 27 deletions.
32 changes: 24 additions & 8 deletions deploy/prod/k8s/aisnode_container/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
# Dockerfile to build an aisnode Docker image
#

FROM ubuntu:22.04 as installer
ARG INSTALLER_IMAGE=debian:bookworm
ARG BUILDER_IMAGE=golang:1.22
ARG BASE_IMAGE=gcr.io/distroless/base-debian12

RUN apt-get update -yq \
&& apt-get install -y --no-install-recommends \

FROM --platform=${TARGETPLATFORM:-linux/amd64} ${INSTALLER_IMAGE} as installer

RUN apt-get update -yq && apt-get install -y --no-install-recommends \
ca-certificates

FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.22 AS builder

FROM --platform=${BUILDPLATFORM:-linux/amd64} ${BUILDER_IMAGE} AS builder

WORKDIR /go/src/aistore

Expand All @@ -24,10 +29,21 @@ RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
make node


FROM ubuntu:22.04 as base
FROM --platform=${TARGETPLATFORM:-linux/amd64} ${BASE_IMAGE} as base

FROM base AS base-amd64
ENV LIB_PATH "x86_64-linux-gnu"

FROM base AS base-arm64
ENV LIB_PATH "aarch64-linux-gnu"

FROM base-${TARGETARCH:-amd64}

COPY --from=installer /usr/lib/${LIB_PATH} /usr/lib/${LIB_PATH}
COPY --from=installer /lib/${LIB_PATH} /lib/${LIB_PATH}
COPY --from=installer /bin/lsblk /bin/lsblk
COPY --from=installer /etc/ssl/certs /etc/ssl/certs

# Copy over the binaries.
COPY --from=builder /go/bin /usr/bin/
COPY --from=installer /etc/ssl /etc/ssl
COPY --from=builder /go/bin/aisnode /usr/bin/aisnode

ENTRYPOINT ["aisnode"]
53 changes: 34 additions & 19 deletions deploy/prod/k8s/aisnode_container/Makefile
Original file line number Diff line number Diff line change
@@ -1,39 +1,54 @@
#
# Usage:
# $ env IMAGE_TAG="3.3" make all
# $ env IMAGE_TAG="3.3" make all_debug
# $ env REGISTRY_URL="docker.io" IMAGE_REPO="aistorage/aisnode" IMAGE_TAG="4.0" AIS_BACKEND_PROVIDERS="aws" make all
# $ env REGISTRY_URL="docker.io" IMAGE_REPO="aistorage/aisnode" IMAGE_TAG="4.0" \
# AIS_BACKEND_PROVIDERS="aws" \
# make all
# $ env REGISTRY_URL="docker.io" IMAGE_REPO="aistorage/aisnode" IMAGE_TAG="4.0-devel" \
# AIS_BACKEND_PROVIDERS="aws" BUILD_MODE="debug" BASE_IMAGE="debian:bookworm" \
# make all
#

DOCKER ?= docker
DOCKER ?= docker
REGISTRY_URL ?= docker.io
IMAGE_REPO ?= aistorage/aisnode
IMAGE_TAG ?= .must_set_in_environment
IMAGE_REPO ?= aistorage/aisnode
IMAGE_TAG ?= .must_set_in_environment

# Image that is used to install necessary packages.
INSTALLER_IMAGE ?=
# Image that is used to build `aisnode` binary.
BUILDER_IMAGE ?=
# Image that is used in final stage.
BASE_IMAGE ?=
# By default we build image in "production" mode. It can be set to `debug`
# to enable extra checks.
BUILD_MODE ?=

BUILD_ARGS = --build-arg "mode=$(BUILD_MODE)" --build-arg "providers=$(AIS_BACKEND_PROVIDERS)"
ifneq ("$(INSTALLER_IMAGE)","")
BUILD_ARGS += --build-arg "INSTALLER_IMAGE=$(INSTALLER_IMAGE)"
endif
ifneq ("$(BUILDER_IMAGE)","")
BUILD_ARGS += --build-arg "BUILDER_IMAGE=$(BUILDER_IMAGE)"
endif
ifneq ("$(BASE_IMAGE)","")
BUILD_ARGS += --build-arg "BASE_IMAGE=$(BASE_IMAGE)"
endif


.PHONY: all all_debug
all: build push
all_debug: build_debug push_debug

.PHONY: build build_debug
.PHONY: build
build:
$(DOCKER) build \
-f Dockerfile \
-t $(REGISTRY_URL)/$(IMAGE_REPO):$(IMAGE_TAG) \
--build-arg providers=$(AIS_BACKEND_PROVIDERS) \
"../../../../."

build_debug:
$(DOCKER) build \
-f Dockerfile \
-t $(REGISTRY_URL)/$(IMAGE_REPO):$(IMAGE_TAG)-debug \
--build-arg mode="debug" --build-arg providers=$(AIS_BACKEND_PROVIDERS) \
$(BUILD_ARGS) \
"../../../../."

.PHONY: push push_debug
.PHONY: push
push:
docker push $(REGISTRY_URL)/$(IMAGE_REPO):$(IMAGE_TAG)

push_debug:
docker push $(REGISTRY_URL)/$(IMAGE_REPO):$(IMAGE_TAG)-debug


0 comments on commit 434a89c

Please sign in to comment.