diff --git a/.github/publish-docker.yml b/.github/publish-docker.yml new file mode 100644 index 000000000..a7eaa880a --- /dev/null +++ b/.github/publish-docker.yml @@ -0,0 +1,108 @@ +name: build-push + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + tags: + - v* + + workflow_dispatch: + +jobs: + dummy: + runs-on: ubuntu-latest + steps: + - name: dummy + run: | + echo "Dummy skip step" + egg-standalone-node: + runs-on: ubuntu-latest + permissions: + packages: write + contents: read + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.9.1 + with: + access_token: ${{ github.token }} + - uses: actions/checkout@v2 + + - name: Build Image + run: ./scripts/build-standalone-docker.sh + + - name: Install docker-slim + run: curl -sL https://raw.githubusercontent.com/docker-slim/docker-slim/master/scripts/install-dockerslim.sh | sudo -E bash - + + - name: Slim down the Image + run: docker-slim build --target webb-tools/egg-standalone-node --http-probe-off --entrypoint egg-standalone-node + + - name: Log into registry + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin + + - name: Push image + run: | + IMAGE_ID=ghcr.io/${{ github.repository_owner }}/egg-standalone-node + + # Change all uppercase to lowercase + IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') + + # Strip git ref prefix from version + VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') + + # Strip "v" prefix from tag name + [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') + + # Use Docker `edge` tag convention + [ "$VERSION" == "main" ] && VERSION=edge + + echo IMAGE_ID=$IMAGE_ID + echo VERSION=$VERSION + docker tag webb-tools/egg-standalone-node.slim $IMAGE_ID:$VERSION + docker push $IMAGE_ID:$VERSION + + egg-parachain-node: + runs-on: ubuntu-latest + permissions: + packages: write + contents: read + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.9.1 + with: + access_token: ${{ github.token }} + - uses: actions/checkout@v2 + + - name: Build Image + run: ./scripts/build-parachain-docker.sh + + - name: Install docker-slim + run: curl -sL https://raw.githubusercontent.com/docker-slim/docker-slim/master/scripts/install-dockerslim.sh | sudo -E bash - + + - name: Slim down the Image + run: docker-slim build --target webb-tools/egg-standalone-node --http-probe-off --entrypoint egg-collator + + - name: Log into registry + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin + + - name: Push image + run: | + IMAGE_ID=ghcr.io/${{ github.repository_owner }}/egg-collator + + # Change all uppercase to lowercase + IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') + + # Strip git ref prefix from version + VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') + + # Strip "v" prefix from tag name + [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') + + # Use Docker `edge` tag convention + [ "$VERSION" == "main" ] && VERSION=edge + + echo IMAGE_ID=$IMAGE_ID + echo VERSION=$VERSION + docker tag webb-tools/egg-collator.slim $IMAGE_ID:$VERSION + docker push $IMAGE_ID:$VERSION diff --git a/docker/Parachain.Dockerfile b/docker/Parachain.Dockerfile index faf2ea2e3..2e5684117 100644 --- a/docker/Parachain.Dockerfile +++ b/docker/Parachain.Dockerfile @@ -1,8 +1,8 @@ FROM rust:buster as builder -WORKDIR /app +WORKDIR /network -RUN rustup default nightly-2021-11-07 && \ - rustup target add wasm32-unknown-unknown --toolchain nightly-2021-11-07 +RUN rustup default nightly-2022-02-01 && \ + rustup target add wasm32-unknown-unknown --toolchain nightly-2022-02-01 # Install Required Packages RUN apt-get update && apt-get install -y git clang curl libssl-dev llvm libudev-dev libgmp3-dev && rm -rf /var/lib/apt/lists/* @@ -13,7 +13,7 @@ ARG BUILD_ARGS COPY . . # Build DKG Parachain Node -RUN cargo build --release -p dkg-node +RUN cargo build --release --locked -p egg-collator # ============= @@ -21,11 +21,11 @@ FROM phusion/baseimage:bionic-1.0.0 RUN useradd -m -u 1000 -U -s /bin/sh -d /dkg dkg -COPY --from=builder /app/target/release/dkg-node /usr/local/bin +COPY --from=builder /network/target/release/egg-collator /usr/local/bin # checks -RUN ldd /usr/local/bin/dkg-node && \ - /usr/local/bin/dkg-node --version +RUN ldd /usr/local/bin/egg-collator && \ + /usr/local/bin/egg-collator --version # Shrinking RUN rm -rf /usr/lib/python* && \ @@ -39,4 +39,4 @@ RUN chown -R dkg:dkg /dkg/data VOLUME ["/dkg/data"] -ENTRYPOINT [ "/usr/local/bin/dkg-node" ] \ No newline at end of file +ENTRYPOINT [ "/usr/local/bin/egg-collator" ] \ No newline at end of file diff --git a/docker/Standalone.Dockerfile b/docker/Standalone.Dockerfile new file mode 100644 index 000000000..817a7e43f --- /dev/null +++ b/docker/Standalone.Dockerfile @@ -0,0 +1,38 @@ +FROM rust:buster as builder +WORKDIR /network + +RUN rustup default nightly-2022-02-01 && \ + rustup target add wasm32-unknown-unknown --toolchain nightly-2022-02-01 + +# Install Required Packages +RUN apt-get update && apt-get install -y git clang curl libssl-dev llvm libudev-dev libgmp3-dev && rm -rf /var/lib/apt/lists/* + +ARG GIT_COMMIT= +ENV GIT_COMMIT=$GIT_COMMIT +ARG BUILD_ARGS + +COPY . . +# Build Standalone Node. +RUN git submodule update --init && \ + cargo build --release --locked -p egg-standalone-node + + +# =============== + +FROM phusion/baseimage:bionic-1.0.0 + +COPY --from=builder /network/target/release/egg-standalone-node /usr/local/bin + +RUN useradd -m -u 1000 -U -s /bin/sh -d /network webb && \ + mkdir -p /data /network/.local/share/webb && \ + chown -R webb:webb /data && \ + ln -s /data /network/.local/share/webb && \ + # Sanity checks + ldd /usr/local/bin/egg-standalone-node && \ + /usr/local/bin/egg-standalone-node --version + +USER webb +EXPOSE 30333 9933 9944 9615 33334 +VOLUME ["/data"] + +ENTRYPOINT [ "/usr/local/bin/egg-standalone-node"] \ No newline at end of file diff --git a/scripts/build-parachain-docker.sh b/scripts/build-parachain-docker.sh new file mode 100644 index 000000000..d0fa0fca6 --- /dev/null +++ b/scripts/build-parachain-docker.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +set -e + +# The following line ensure we run from the project root +PROJECT_ROOT=`git rev-parse --show-toplevel` +cd $PROJECT_ROOT + +VERSION=`grep "^version" ./node/Cargo.toml | egrep -o "([0-9\.]+)"` +NODE_NAME=ghcr.io/webb-tools/egg-collator +BUILD_ARGS="cargo build --release -p dkg-node" + +docker build -f ./docker/Parachain.Dockerfile . -t $NODE_NAME:$VERSION --build-arg GIT_COMMIT=${VERSION} --build-arg BUILD_ARGS="$BUILD_ARGS" +docker push $NODE_NAME:$VERSION \ No newline at end of file diff --git a/scripts/build-protocol-substrate-docker.sh b/scripts/build-protocol-substrate-docker.sh new file mode 100644 index 000000000..6eabb96c3 --- /dev/null +++ b/scripts/build-protocol-substrate-docker.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +set -e + +pushd . + +# The following line ensure we run from the project root +PROJECT_ROOT=`git rev-parse --show-toplevel` +cd $PROJECT_ROOT + +# Find the current version from Cargo.toml +VERSION=`grep "^version" ./standalone/node/Cargo.toml | egrep -o "([0-9\.]+)"` +GITUSER=webb-tools +IMAGE_NAME=protocol-substrate-standalone-node + +# Build the image +echo "Building ${GITUSER}/${IMAGE_NAME}:latest docker image, hang on!" +time docker build -f ./docker/Standalone.Dockerfile -t ${GITUSER}/${IMAGE_NAME}:latest . +docker tag ${GITUSER}/${IMAGE_NAME}:latest ${GITUSER}/${IMAGE_NAME}:v${VERSION} + +# Show the list of available images for this repo +echo "Image is ready" +docker images | grep ${IMAGE_NAME} + +popd diff --git a/scripts/build-standalone-docker.sh b/scripts/build-standalone-docker.sh new file mode 100644 index 000000000..8f90521ad --- /dev/null +++ b/scripts/build-standalone-docker.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +set -e + +pushd . + +# The following line ensure we run from the project root +PROJECT_ROOT=`git rev-parse --show-toplevel` +cd $PROJECT_ROOT + +# Find the current version from Cargo.toml +VERSION=`grep "^version" ./standalone/node/Cargo.toml | egrep -o "([0-9\.]+)"` +GITUSER=webb-tools +IMAGE_NAME=egg-standalone-node + +# Build the image +echo "Building ${GITUSER}/${IMAGE_NAME}:latest docker image, hang on!" +time docker build -f ./docker/Standalone.Dockerfile -t ${GITUSER}/${IMAGE_NAME}:latest . +docker tag ${GITUSER}/${IMAGE_NAME}:latest ${GITUSER}/${IMAGE_NAME}:v${VERSION} + +# Show the list of available images for this repo +echo "Image is ready" +docker images | grep ${IMAGE_NAME} + +popd