Skip to content

Commit

Permalink
dockerfile (#155)
Browse files Browse the repository at this point in the history
* dockerfile

* update dockerfile

* fix release
  • Loading branch information
xlc authored Oct 9, 2024
1 parent 6586caf commit bd4d182
Show file tree
Hide file tree
Showing 8 changed files with 282 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/.build
.lib
.git
.vscode
*.Dockerfile
44 changes: 44 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: docker

on:
push:
branches:
- master
tags:
- '*'

jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: acala/${{ github.event.repository.name }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=ref,event=tag
type=sha
type=sha,format=long
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
file: scripts/release.Dockerfile
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Utils

// TODO: add tests
public actor InMemoryDataProvider: Sendable {
public private(set) var heads: Set<Data32>
public private(set) var finalizedHead: Data32
Expand Down
Binary file added Boka/boka
Binary file not shown.
22 changes: 22 additions & 0 deletions scripts/build-external-libs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

set -e

release=v7

mkdir -p .lib
cd .lib

# check if the external libs are already cloned
if [ ! -d "boka-external-libs" ]; then
git clone https://github.com/open-web3-stack/boka-external-libs --recurse-submodules --shallow-submodules
fi
cd boka-external-libs
git fetch
git checkout $release
./scripts/msquic.sh

system=$(uname -s)
arch=$(uname -m)

mv build/$system-$arch/* ..
104 changes: 104 additions & 0 deletions scripts/dev.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
FROM swift:6.0-noble AS builder
WORKDIR /boka

RUN apt-get update && \
apt-get dist-upgrade -y -o Dpkg::Options::="--force-confold" && \
apt-get install -y curl build-essential cmake librocksdb-dev libzstd-dev libbz2-dev liblz4-dev

# install rust
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y

ENV PATH="/root/.cargo/bin:${PATH}"

COPY . .

RUN make deps

WORKDIR /boka/Boka

RUN swift build

RUN cp $(swift build --show-bin-path)/Boka /boka/boka-bin

WORKDIR /boka

# RUN ./boka-bin --help

# =============

FROM phusion/baseimage:noble-1.0.0
LABEL maintainer="[email protected]"

# from https://github.com/swiftlang/swift-docker/blob/38e4244ebab3d6a4e702fb30449827d6c28ee1fd/6.0/ubuntu/24.04/slim/Dockerfile
RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true && apt-get -q update && \
apt-get -q install -y \
libcurl4 \
libxml2 \
tzdata \
&& rm -r /var/lib/apt/lists/*

# Everything up to here should cache nicely between Swift versions, assuming dev dependencies change little

# pub rsa4096 2024-09-16 [SC] [expires: 2026-09-16]
# 52BB7E3DE28A71BE22EC05FFEF80A866B47A981F
# uid [ unknown] Swift 6.x Release Signing Key <[email protected]>
ARG SWIFT_SIGNING_KEY=52BB7E3DE28A71BE22EC05FFEF80A866B47A981F
ARG SWIFT_PLATFORM=ubuntu24.04
ARG SWIFT_BRANCH=swift-6.0.1-release
ARG SWIFT_VERSION=swift-6.0.1-RELEASE
ARG SWIFT_WEBROOT=https://download.swift.org

ENV SWIFT_SIGNING_KEY=$SWIFT_SIGNING_KEY \
SWIFT_PLATFORM=$SWIFT_PLATFORM \
SWIFT_BRANCH=$SWIFT_BRANCH \
SWIFT_VERSION=$SWIFT_VERSION \
SWIFT_WEBROOT=$SWIFT_WEBROOT

RUN set -e; \
ARCH_NAME="$(dpkg --print-architecture)"; \
url=; \
case "${ARCH_NAME##*-}" in \
'amd64') \
OS_ARCH_SUFFIX=''; \
;; \
'arm64') \
OS_ARCH_SUFFIX='-aarch64'; \
;; \
*) echo >&2 "error: unsupported architecture: '$ARCH_NAME'"; exit 1 ;; \
esac; \
SWIFT_WEBDIR="$SWIFT_WEBROOT/$SWIFT_BRANCH/$(echo $SWIFT_PLATFORM | tr -d .)$OS_ARCH_SUFFIX" \
&& SWIFT_BIN_URL="$SWIFT_WEBDIR/$SWIFT_VERSION/$SWIFT_VERSION-$SWIFT_PLATFORM$OS_ARCH_SUFFIX.tar.gz" \
&& SWIFT_SIG_URL="$SWIFT_BIN_URL.sig" \
# - Grab curl and gpg here so we cache better up above
&& export DEBIAN_FRONTEND=noninteractive \
&& apt-get -q update && apt-get -q install -y curl gnupg && rm -rf /var/lib/apt/lists/* \
# - Download the GPG keys, Swift toolchain, and toolchain signature, and verify.
&& export GNUPGHOME="$(mktemp -d)" \
&& curl -fsSL "$SWIFT_BIN_URL" -o swift.tar.gz "$SWIFT_SIG_URL" -o swift.tar.gz.sig \
&& gpg --batch --quiet --keyserver keyserver.ubuntu.com --recv-keys "$SWIFT_SIGNING_KEY" \
&& gpg --batch --verify swift.tar.gz.sig swift.tar.gz \
# - Unpack the toolchain, set libs permissions, and clean up.
&& tar -xzf swift.tar.gz --directory / --strip-components=1 \
$SWIFT_VERSION-$SWIFT_PLATFORM$OS_ARCH_SUFFIX/usr/lib/swift/linux \
$SWIFT_VERSION-$SWIFT_PLATFORM$OS_ARCH_SUFFIX/usr/libexec/swift/linux \
&& chmod -R o+r /usr/lib/swift /usr/libexec/swift \
&& rm -rf "$GNUPGHOME" swift.tar.gz.sig swift.tar.gz \
&& apt-get purge --auto-remove -y curl gnupg

RUN useradd -m -u 1001 -U -s /bin/sh -d /boka boka

COPY --from=builder /boka/boka-bin /usr/local/bin/boka

# checks
RUN ldd /usr/local/bin/boka && \
/usr/local/bin/boka --help

USER boka

EXPOSE 9955

RUN mkdir /boka/data

VOLUME ["/boka/data"]

ENTRYPOINT ["/usr/local/bin/boka"]
4 changes: 2 additions & 2 deletions scripts/external-libs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

release=v6
release=v7

os=$(uname -s)
arch=$(uname -m)
Expand All @@ -15,7 +15,7 @@ fi

cd .lib

curl -L -o "$filename" "https://github.com/AcalaNetwork/boka-external-libs/releases/download/$release/$filename"
curl -L -o "$filename" "https://github.com/open-web3-stack/boka-external-libs/releases/download/$release/$filename"

tar -xvf "$filename"

Expand Down
105 changes: 105 additions & 0 deletions scripts/release.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
FROM swift:6.0-noble AS builder
WORKDIR /boka

RUN apt-get update && \
apt-get dist-upgrade -y -o Dpkg::Options::="--force-confold" && \
apt-get install -y curl build-essential cmake librocksdb-dev libzstd-dev libbz2-dev liblz4-dev

# install rust
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y

ENV PATH="/root/.cargo/bin:${PATH}"

COPY . .

RUN ./scripts/build-external-libs.sh
RUN make deps

WORKDIR /boka/Boka

RUN swift build -c release

RUN cp $(swift build --show-bin-path -c release)/Boka /boka/boka-bin

WORKDIR /boka

# RUN ./boka-bin --help

# =============

FROM phusion/baseimage:noble-1.0.0
LABEL maintainer="[email protected]"

# from https://github.com/swiftlang/swift-docker/blob/38e4244ebab3d6a4e702fb30449827d6c28ee1fd/6.0/ubuntu/24.04/slim/Dockerfile
RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true && apt-get -q update && \
apt-get -q install -y \
libcurl4 \
libxml2 \
tzdata \
&& rm -r /var/lib/apt/lists/*

# Everything up to here should cache nicely between Swift versions, assuming dev dependencies change little

# pub rsa4096 2024-09-16 [SC] [expires: 2026-09-16]
# 52BB7E3DE28A71BE22EC05FFEF80A866B47A981F
# uid [ unknown] Swift 6.x Release Signing Key <[email protected]>
ARG SWIFT_SIGNING_KEY=52BB7E3DE28A71BE22EC05FFEF80A866B47A981F
ARG SWIFT_PLATFORM=ubuntu24.04
ARG SWIFT_BRANCH=swift-6.0.1-release
ARG SWIFT_VERSION=swift-6.0.1-RELEASE
ARG SWIFT_WEBROOT=https://download.swift.org

ENV SWIFT_SIGNING_KEY=$SWIFT_SIGNING_KEY \
SWIFT_PLATFORM=$SWIFT_PLATFORM \
SWIFT_BRANCH=$SWIFT_BRANCH \
SWIFT_VERSION=$SWIFT_VERSION \
SWIFT_WEBROOT=$SWIFT_WEBROOT

RUN set -e; \
ARCH_NAME="$(dpkg --print-architecture)"; \
url=; \
case "${ARCH_NAME##*-}" in \
'amd64') \
OS_ARCH_SUFFIX=''; \
;; \
'arm64') \
OS_ARCH_SUFFIX='-aarch64'; \
;; \
*) echo >&2 "error: unsupported architecture: '$ARCH_NAME'"; exit 1 ;; \
esac; \
SWIFT_WEBDIR="$SWIFT_WEBROOT/$SWIFT_BRANCH/$(echo $SWIFT_PLATFORM | tr -d .)$OS_ARCH_SUFFIX" \
&& SWIFT_BIN_URL="$SWIFT_WEBDIR/$SWIFT_VERSION/$SWIFT_VERSION-$SWIFT_PLATFORM$OS_ARCH_SUFFIX.tar.gz" \
&& SWIFT_SIG_URL="$SWIFT_BIN_URL.sig" \
# - Grab curl and gpg here so we cache better up above
&& export DEBIAN_FRONTEND=noninteractive \
&& apt-get -q update && apt-get -q install -y curl gnupg && rm -rf /var/lib/apt/lists/* \
# - Download the GPG keys, Swift toolchain, and toolchain signature, and verify.
&& export GNUPGHOME="$(mktemp -d)" \
&& curl -fsSL "$SWIFT_BIN_URL" -o swift.tar.gz "$SWIFT_SIG_URL" -o swift.tar.gz.sig \
&& gpg --batch --quiet --keyserver keyserver.ubuntu.com --recv-keys "$SWIFT_SIGNING_KEY" \
&& gpg --batch --verify swift.tar.gz.sig swift.tar.gz \
# - Unpack the toolchain, set libs permissions, and clean up.
&& tar -xzf swift.tar.gz --directory / --strip-components=1 \
$SWIFT_VERSION-$SWIFT_PLATFORM$OS_ARCH_SUFFIX/usr/lib/swift/linux \
$SWIFT_VERSION-$SWIFT_PLATFORM$OS_ARCH_SUFFIX/usr/libexec/swift/linux \
&& chmod -R o+r /usr/lib/swift /usr/libexec/swift \
&& rm -rf "$GNUPGHOME" swift.tar.gz.sig swift.tar.gz \
&& apt-get purge --auto-remove -y curl gnupg

RUN useradd -m -u 1001 -U -s /bin/sh -d /boka boka

COPY --from=builder /boka/boka-bin /usr/local/bin/boka

# checks
RUN ldd /usr/local/bin/boka && \
/usr/local/bin/boka --help

USER boka

EXPOSE 9955

RUN mkdir /boka/data

VOLUME ["/boka/data"]

ENTRYPOINT ["/usr/local/bin/boka"]

0 comments on commit bd4d182

Please sign in to comment.