Skip to content

Commit

Permalink
Fix Elrond ARM image creation
Browse files Browse the repository at this point in the history
Signed-off-by: Stavros Foteinopoulos <[email protected]>
  • Loading branch information
stafot committed Dec 21, 2023
1 parent 00160c3 commit b41fe7e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
31 changes: 23 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## Docker Build Versions
DOCKER_BUILD_IMAGE = golang:1.20
DOCKER_BASE_IMAGE = alpine:3.15.4
DOCKER_BASE_IMAGE = alpine:3.19

################################################################################

Expand Down Expand Up @@ -65,14 +65,27 @@ binaries: ## Build binaries of elrond
.PHONY: build
build: ## Build the elrond
@echo Building Elrond
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 $(GO) build -ldflags '$(LDFLAGS)' -gcflags all=-trimpath=$(PWD) -asmflags all=-trimpath=$(PWD) -a -installsuffix cgo -o build/_output/bin/elrond ./cmd/$(APP)
@echo Building Mattermost-Cloud for ARCH=$(ARCH)
@if [ "$(ARCH)" = "amd64" ]; then \
export GOARCH="amd64"; \
elif [ "$(ARCH)" = "arm64" ]; then \
export GOARCH="arm64"; \
elif [ "$(ARCH)" = "arm" ]; then \
export GOARCH="arm"; \
else \
echo "Unknown architecture $(ARCH)"; \
exit 1; \
fi; \
GOOS=linux CGO_ENABLED=0 $(GO) build -ldflags '$(LDFLAGS)' -gcflags all=-trimpath=$(PWD) -asmflags all=-trimpath=$(PWD) -a -installsuffix cgo -o build/_output/bin/elrond ./cmd/$(APP)

.PHONY: build-image
build-image: ## Build the docker image for Elrond
@echo Building Elrond Docker Image
: $${DOCKER_USERNAME:?}
: $${DOCKER_PASSWORD:?}
echo $(DOCKER_PASSWORD) | docker login --username $(DOCKER_USERNAME) --password-stdin
@if [ -z "$(DOCKER_USERNAME)" ] || [ -z "$(DOCKER_PASSWORD)" ]; then \
echo "DOCKER_USERNAME and/or DOCKER_PASSWORD not set. Skipping Docker login."; \
else \
echo $(DOCKER_PASSWORD) | docker login --username $(DOCKER_USERNAME) --password-stdin; \
fi
docker buildx build \
--platform linux/arm64,linux/amd64 \
--build-arg DOCKER_BUILD_IMAGE=$(DOCKER_BUILD_IMAGE) \
Expand All @@ -84,10 +97,12 @@ build-image: ## Build the docker image for Elrond
.PHONY: build-image-with-tag
build-image-with-tag: ## Build the docker image for elrond
@echo Building Elrond Docker Image
: $${DOCKER_USERNAME:?}
: $${DOCKER_PASSWORD:?}
@if [ -z "$(DOCKER_USERNAME)" ] || [ -z "$(DOCKER_PASSWORD)" ]; then \
echo "DOCKER_USERNAME and/or DOCKER_PASSWORD not set. Skipping Docker login."; \
else \
echo $(DOCKER_PASSWORD) | docker login --username $(DOCKER_USERNAME) --password-stdin; \
fi
: $${TAG:?}
echo $(DOCKER_PASSWORD) | docker login --username $(DOCKER_USERNAME) --password-stdin
docker buildx build \
--platform linux/arm64,linux/amd64 \
--build-arg DOCKER_BUILD_IMAGE=$(DOCKER_BUILD_IMAGE) \
Expand Down
17 changes: 14 additions & 3 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
# Build the Mattermost Elrond
ARG DOCKER_BUILD_IMAGE=golang:1.20
ARG DOCKER_BASE_IMAGE=alpine:3.16.2
ARG DOCKER_BASE_IMAGE=alpine:3.19

FROM ${DOCKER_BUILD_IMAGE} AS build
WORKDIR /elrond/
COPY . /elrond/

# Detect architecture and set ARCH
RUN ARCH=$(uname -m) && \
if [ "$ARCH" = "x86_64" ]; then \
ARCH="amd64"; \
elif [ "$ARCH" = "aarch64" ]; then \
ARCH="arm64"; \
elif [ "$ARCH" = "armv7l" ] || [ "$ARCH" = "armv6l" ]; then \
ARCH="arm"; \
fi && \
echo "ARCH=$ARCH" && \
make build ARCH=$ARCH
RUN apt-get update -yq && apt-get install -yq unzip
RUN make build


# Final Image
Expand All @@ -24,7 +35,7 @@ ENV ELROND=/elrond/elrond \
USER_NAME=elrond

RUN apk update && apk add libc6-compat && apk add ca-certificates
COPY --from=build /elrond/build/_output/bin/elrond /elrond/elrond
COPY --from=build /elrond/cmd/elrond /elrond/elrond
COPY --from=build /elrond/build/bin /usr/local/bin

RUN /usr/local/bin/user_setup
Expand Down

0 comments on commit b41fe7e

Please sign in to comment.