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

♻️ refactor the CI to support Multi Platforms #9

Closed
wants to merge 2 commits into from
Closed
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
50 changes: 0 additions & 50 deletions .github/workflows/docker-build.yaml

This file was deleted.

25 changes: 16 additions & 9 deletions .github/workflows/docker-test.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
name: Task - Build Docker Image

on:
Expand All @@ -10,6 +9,7 @@ jobs:
strategy:
matrix:
package: [docker/sui-node]
platform: [linux/amd64, linux/386]
runs-on: ubuntu-latest
permissions:
checks: write
Expand All @@ -21,25 +21,32 @@ jobs:
with:
fetch-depth: 0
- name: Set up QEMU
uses: docker/[email protected]
uses: docker/[email protected]

- name: Set up Docker Buildx
uses: docker/[email protected]
with:
buildkitd-flags: --debug

- name: Create Docker Args
id: Docker_args
id: docker_args
shell: bash
run: |
# Set the necessary environment variables for the Docker build
GIT_REVISION="$(git describe --always --abbrev=12 --dirty --exclude '*')"
BUILD_DATE="$(date -u +'%Y-%m-%d')"
echo "git_revision=${GIT_REVISION}" >> $GITHUB_OUTPUT
echo "build_date=${BUILD_DATE}" >> $GITHUB_OUTPUT

echo "GIT_REVISION=$GIT_REVISION" >> $GITHUB_ENV
echo "BUILD_DATE=$BUILD_DATE" >> $GITHUB_ENV
- name: Build and push Sui Node
- name: Build Sui Node
uses: docker/[email protected]
with:
context: .
file: ./${{ matrix.package }}/Dockerfile
push: false
load: false
platforms: ${{ matrix.platform }}
build-args: |
GIT_REVISION=${{ steps.Docker_args.outputs.GIT_REVISION }}
BUILD_DATE=${{ steps.Docker_args.outputs.BUILD_DATE }}
GIT_REVISION=${{ steps.docker_args.outputs.git_revision }}
BUILD_DATE=${{ steps.docker_args.outputs.build_date }}
cache-from: type=gha,scope=${{ matrix.platform }}
cache-to: type=gha,scope=${{ matrix.platform }},mode=max
62 changes: 59 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,68 @@
---
name: Workflow - Release

on:
workflow_dispatch:
inputs:
version:
description: 'Version to release (e.g., devnet-0.0.1)'
required: true
release:
types: [published]

jobs:
docker_release_build:
name: Build docker release
uses: ./.github/workflows/docker-build.yaml
name: Build and tag docker release
permissions:
contents: read
packages: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract version
id: version
run: |
if [ "${{ github.event_name }}" == "release" ]; then
VERSION=${GITHUB_REF#refs/tags/}
else
VERSION=${{ github.event.inputs.version }}
fi
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT

- name: Create Docker Args
id: docker_args
shell: bash
run: |
GIT_REVISION="$(git describe --always --abbrev=12 --dirty --exclude '*')"
BUILD_DATE="$(date -u +'%Y-%m-%d')"
echo "GIT_REVISION=${GIT_REVISION}" >> $GITHUB_OUTPUT
echo "BUILD_DATE=${BUILD_DATE}" >> $GITHUB_OUTPUT

- name: Build and push Sui Node
uses: docker/build-push-action@v6
with:
context: .
file: ./docker/sui-node/Dockerfile
push: true
platforms: linux/amd64,linux/386
build-args: |
GIT_REVISION=${{ steps.docker_args.outputs.GIT_REVISION }}
BUILD_DATE=${{ steps.docker_args.outputs.BUILD_DATE }}
tags: |
ghcr.io/${{ github.repository }}/docker/sui-node:latest
ghcr.io/${{ github.repository }}/docker/sui-node:${{ steps.version.outputs.VERSION }}
labels: |
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.description=Public Pui Node Docker image
org.opencontainers.image.version=${{ steps.version.outputs.VERSION }}
org.opencontainers.image.licenses=Apache-2.0
55 changes: 41 additions & 14 deletions docker/sui-node/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,35 +1,62 @@
# Build application
#
# Copy in all crates, Cargo.toml and Cargo.lock unmodified,
# and build the application.
FROM rust:1.81-bullseye AS builder

ARG TARGETARCH
ARG PROFILE=release
ARG GIT_REVISION
ENV GIT_REVISION=$GIT_REVISION
WORKDIR "$WORKDIR/sui"
WORKDIR "/sui"

# Install build dependencies
RUN apt-get update && apt-get install -y cmake clang

# Copy source files
COPY Cargo.toml Cargo.lock ./
COPY consensus consensus
COPY crates crates
COPY sui-execution sui-execution
COPY external-crates external-crates

RUN cargo build --profile ${PROFILE} --bin sui-node
# Set up cross-compilation targets if needed
RUN rustup target add i686-unknown-linux-gnu

# Build for the appropriate architecture
RUN case ${TARGETARCH} in \
"amd64") cargo build --profile ${PROFILE} --bin sui-node ;; \
"386") cargo build --profile ${PROFILE} --target i686-unknown-linux-gnu --bin sui-node ;; \
*) echo "Unsupported architecture: ${TARGETARCH}" && exit 1 ;; \
esac

# Production Image
FROM debian:bullseye-slim AS runtime
# Use jemalloc as memory allocator
RUN apt-get update && apt-get install -y libjemalloc-dev ca-certificates curl
ENV LD_PRELOAD /usr/lib/x86_64-linux-gnu/libjemalloc.so

ARG TARGETARCH
ARG PROFILE=release
WORKDIR "$WORKDIR/sui"
# Both bench and release profiles copy from release dir
COPY --from=builder /sui/target/release/sui-node /opt/sui/bin/sui-node
# Support legacy usages of /usr/local/bin/sui-node
COPY --from=builder /sui/target/release/sui-node /usr/local/bin

# Install architecture-specific dependencies
RUN apt-get update && apt-get install -y ca-certificates curl \
&& case ${TARGETARCH} in \
"amd64") apt-get install -y libjemalloc-dev && \
echo "/usr/lib/x86_64-linux-gnu/libjemalloc.so" > /etc/ld.preload ;; \
"386") apt-get install -y libjemalloc-dev && \
echo "/usr/lib/i386-linux-gnu/libjemalloc.so" > /etc/ld.preload ;; \
esac

WORKDIR "/sui"

# Copy the binary based on architecture
COPY --from=builder /sui/target/${TARGETARCH}/release/sui-node /opt/sui/bin/sui-node
# Support legacy usages
COPY --from=builder /sui/target/${TARGETARCH}/release/sui-node /usr/local/bin

ARG BUILD_DATE
ARG GIT_REVISION

LABEL build-date=$BUILD_DATE
LABEL git-revision=$GIT_REVISION
LABEL git-revision=$GIT_REVISION
LABEL org.opencontainers.image.description="PUI Node"
LABEL org.opencontainers.image.licenses="Apache-2.0"

ENV PATH="/opt/sui/bin:${PATH}"

ENTRYPOINT ["/opt/sui/bin/sui-node"]
Loading