Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Elrond ARM image creation #26

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 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 @@ -64,15 +64,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 Elrond 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 +96,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