Skip to content

Commit

Permalink
Initial linux arm64 support (#39)
Browse files Browse the repository at this point in the history
* init linux arm image

* Update ci image

* Fix

* make base image multi-arch

* Update publish script

* Update script

* Fix script

* Restore push

* Update script

* Fix

* Update base

* Use latest tag
  • Loading branch information
anakinxc authored Jul 18, 2023
1 parent e0cfdf1 commit 83c0883
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 29 deletions.
65 changes: 65 additions & 0 deletions dockerfiles/release-ci-aarch64.DockerFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
FROM centos:centos8

# GCC version
ARG DEVTOOLSET_VERSION=11

RUN cd /etc/yum.repos.d/ \
&& sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-* \
&& sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*

RUN yum update -y \
&& yum install -y dnf-plugins-core \
&& yum clean all

RUN yum config-manager --set-enabled powertools

# install devtools and [enable it](https://access.redhat.com/solutions/527703)
RUN yum install -y \
gcc-toolset-${DEVTOOLSET_VERSION}-gcc \
gcc-toolset-${DEVTOOLSET_VERSION}-gcc-c++ \
gcc-toolset-${DEVTOOLSET_VERSION}-binutils \
git vim-common wget unzip which java-11-openjdk-devel.aarch64 \
libtool autoconf make ninja-build \
&& yum clean all \
&& echo "source scl_source enable gcc-toolset-${DEVTOOLSET_VERSION}" > /etc/profile.d/enable_gcc_toolset.sh

ENV PATH="/opt/rh/gcc-toolset-${DEVTOOLSET_VERSION}/root/usr/bin:${PATH}"

RUN wget https://github.com/Kitware/CMake/releases/download/v3.26.3/cmake-3.26.3-linux-aarch64.sh \
&& sh cmake-3.26.3-linux-aarch64.sh --prefix=/usr --skip-license \
&& rm -f cmake-3.26.3-linux-aarch64.sh

# install conda
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-aarch64.sh \
&& bash Miniconda3-latest-Linux-aarch64.sh -b \
&& rm -f Miniconda3-latest-Linux-aarch64.sh \
&& /root/miniconda3/bin/conda init bash

# install go
ARG GO_VERSION=1.19.10
ARG GO_SHA256SUM="df98698821211c819e8b2420c77a0f802d989e377718578a31b1f91f6be2c5b4"

# install go
RUN set -eux; \
url="https://golang.google.cn/dl/go${GO_VERSION}.linux-arm64.tar.gz"; \
wget --no-check-certificate -O go.tgz "$url"; \
echo "${GO_SHA256SUM} *go.tgz" | sha256sum -c -; \
tar -C /usr/local -xzf go.tgz; \
rm go.tgz;

ENV GOPATH="/usr/local"
ENV PATH="/usr/local/go/bin:${GOPATH}/bin:${PATH}"

# install bazel
# RUN wget https://github.com/bazelbuild/bazel/releases/download/5.4.1/bazel-5.4.1-linux-arm64 \
RUN wget https://mirrors.huaweicloud.com/bazel/5.4.1/bazel-5.4.1-linux-arm64 \
&& mv bazel-5.4.1-linux-arm64 /usr/bin/bazel \
&& chmod +x /usr/bin/bazel

# Add conda to path
ENV PATH="/root/miniconda3/bin:${PATH}"

# run as root for now
WORKDIR /home/admin/

ENTRYPOINT [ "/bin/bash", "-l" ]
18 changes: 8 additions & 10 deletions dockerfiles/spu-ci.DockerFile
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
# Base image contains c++ toolchain and python
# These should be consistant across all Secretflow dockers
FROM secretflow/ubuntu-base-ci:0.4
FROM secretflow/ubuntu-base-ci:latest

ARG GO_VERSION=1.19.7
ARG GO_SHA256SUM="7a75720c9b066ae1750f6bcc7052aba70fa3813f4223199ee2a2315fd3eb533d"
ARG TARGETPLATFORM

ARG GO_VERSION=1.19.10

# Required by grpc
# install go
RUN set -eux; \
url="https://golang.google.cn/dl/go${GO_VERSION}.linux-amd64.tar.gz"; \
wget --no-check-certificate -O go.tgz "$url"; \
echo "${GO_SHA256SUM} *go.tgz" | sha256sum -c -; \
tar -C /usr/local -xzf go.tgz; \
rm go.tgz;
RUN if [ "$TARGETPLATFORM" = "linux/amd64" ] ; then GO_ARCH=amd64 ; else GO_ARCH=arm64 ; fi \
&& wget --no-check-certificate -O go.tgz https://golang.google.cn/dl/go${GO_VERSION}.linux-$GO_ARCH.tar.gz \
&& tar -C /usr/local -xzf go.tgz \
&& rm go.tgz

ENV GOPATH="/usr/local"
ENV PATH="/usr/local/go/bin:${GOPATH}/bin:${PATH}"
18 changes: 13 additions & 5 deletions dockerfiles/ubuntu-base-ci.DockerFile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ FROM ubuntu:jammy

LABEL maintainer="secretflow-contact@service.alipay.com"

ARG TARGETPLATFORM

# change dash to bash as default shell
RUN ln -sf /usr/bin/bash /bin/sh

Expand All @@ -15,10 +17,14 @@ RUN apt-get update \
&& update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 11 \
&& ln -s /usr/bin/ld.lld-15 /usr/bin/ld.lld

# amd64 is only reqiured on amd64 platform
RUN if [ "$TARGETPLATFORM" = "linux/amd64" ] ; then apt install -y nasm ; fi

# install conda
RUN wget https://repo.anaconda.com/miniconda/Miniconda3-py38_23.1.0-1-Linux-x86_64.sh \
&& bash Miniconda3-py38_23.1.0-1-Linux-x86_64.sh -b \
&& rm -f Miniconda3-py38_23.1.0-1-Linux-x86_64.sh \
RUN if [ "$TARGETPLATFORM" = "linux/arm64" ] ; then CONDA_ARCH=aarch64 ; else CONDA_ARCH=x86_64 ; fi \
&& wget https://repo.anaconda.com/miniconda/Miniconda3-py38_23.5.2-0-Linux-$CONDA_ARCH.sh \
&& bash Miniconda3-py38_23.5.2-0-Linux-$CONDA_ARCH.sh -b \
&& rm -f Miniconda3-py38_23.5.2-0-Linux-$CONDA_ARCH.sh \
&& /root/miniconda3/bin/conda init \
&& /root/miniconda3/bin/conda update --all -y \
&& /root/miniconda3/bin/pip list -o | cut -f1 -d' ' | tr " " "\n" | awk '{if(NR>=3)print}' | cut -d' ' -f1 | xargs -n1 /root/miniconda3/bin/pip install -U \
Expand All @@ -35,8 +41,10 @@ RUN rm -f /root/miniconda3/lib/libstdc++.so.6 \
RUN ln -s /root/miniconda3/bin/python3 /usr/bin/python3

# install bazel
RUN wget https://github.com/bazelbuild/bazel/releases/download/5.4.1/bazel-5.4.1-installer-linux-x86_64.sh \
&& bash ./bazel-5.4.1-installer-linux-x86_64.sh && rm -f ./bazel-5.4.1-installer-linux-x86_64.sh
RUN if [ "$TARGETPLATFORM" = "linux/arm64" ] ; then BAZEL_ARCH=arm64 ; else BAZEL_ARCH=x86_64 ; fi \
&& wget https://mirrors.huaweicloud.com/bazel/5.4.1/bazel-5.4.1-linux-$BAZEL_ARCH \
&& mv bazel-5.4.1-linux-$BAZEL_ARCH /usr/bin/bazel \
&& chmod +x /usr/bin/bazel

# run as root for now
WORKDIR /home/admin/
Expand Down
103 changes: 89 additions & 14 deletions publish_docker_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,24 @@
import subprocess


def run_shell_command_with_live_output(cmd, cwd):
def _run_shell_command_with_live_output(cmd, cwd, check=True):
print(cmd)
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=cwd)
for line in p.stdout:
print(line.decode("utf-8").rstrip())
p.wait()
status = p.poll()
assert status == 0
if check:
assert status == 0


def _check_is_multiarch_dockerfile(file):
with open(file, "r") as df:
content = df.read()
if "TARGETPLATFORM" in content:
return True
else:
return False


COLOR_GREEN = "\033[92m"
Expand Down Expand Up @@ -57,18 +67,83 @@ def main():
versioned_tag = f"secretflow/{args.name}:{args.tag}"
latest_tag = f"secretflow/{args.name}:latest"

print(f"{COLOR_GREEN}[1/4] Build docker image {args.name}{COLOR_END}")
run_shell_command_with_live_output(
["docker", "build", "--no-cache", ".", "-f", dockerfile, "-t", versioned_tag], "."
)
print(f"{COLOR_GREEN}[2/4] Tag image with latest{COLOR_END}")
run_shell_command_with_live_output(
["docker", "tag", versioned_tag, latest_tag], "."
)
print(f"{COLOR_GREEN}[3/4] Push versioned tag to registry{COLOR_END}")
run_shell_command_with_live_output(["docker", "push", versioned_tag], ".")
print(f"{COLOR_GREEN}[4/4] Push latest tag to registry{COLOR_END}")
run_shell_command_with_live_output(["docker", "push", latest_tag], ".")
print(f"{COLOR_GREEN}Build docker image {args.name}{COLOR_END}")

if _check_is_multiarch_dockerfile(dockerfile):
print(f"{COLOR_GREEN}Creating buildx")
is_multi_arch = True
_run_shell_command_with_live_output(
[
"docker",
"buildx",
"create",
"--name",
"sf-image-builder",
"--platform",
"linux/amd64,linux/arm64",
"--use",
],
".",
check=False,
)
# Build using buildx
_run_shell_command_with_live_output(
[
"docker",
"buildx",
"build",
"--platform",
"linux/amd64,linux/arm64",
"--no-cache",
".",
"-f",
dockerfile,
"-t",
versioned_tag,
"--push"
],
".",
)
print(f"{COLOR_GREEN}Build latest docker image {args.name}{COLOR_END}")
_run_shell_command_with_live_output(
[
"docker",
"buildx",
"build",
"--platform",
"linux/amd64,linux/arm64",
".",
"-f",
dockerfile,
"-t",
latest_tag,
"--push"
],
".",
)
else:
_run_shell_command_with_live_output(
[
"docker",
"build",
"--no-cache",
".",
"-f",
dockerfile,
"-t",
versioned_tag,
],
".",
)
print(f"{COLOR_GREEN}[2/4] Tag image with latest{COLOR_END}")
_run_shell_command_with_live_output(
["docker", "tag", versioned_tag, latest_tag], "."
)
print(f"{COLOR_GREEN}[3/4] Push versioned tag to registry{COLOR_END}")
_run_shell_command_with_live_output(["docker", "push", versioned_tag], ".")
print(f"{COLOR_GREEN}[4/4] Push latest tag to registry{COLOR_END}")
_run_shell_command_with_live_output(["docker", "push", latest_tag], ".")



if __name__ == "__main__":
Expand Down

0 comments on commit 83c0883

Please sign in to comment.