Skip to content

Commit

Permalink
Merge pull request AleoNet#1895 from AleoHQ/docker-builds
Browse files Browse the repository at this point in the history
Upgrading Dockerfile to Ubuntu 22.04
  • Loading branch information
howardwu authored Oct 19, 2022
2 parents 64046c9 + 00abaea commit 1646ed8
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 29 deletions.
49 changes: 27 additions & 22 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ commands:
export WORK_DIR="$CIRCLE_WORKING_DIRECTORY/.cache/sccache"
export SCCACHE_DIR="$CIRCLE_WORKING_DIRECTORY/.cache/sccache"
mkdir -p "$CIRCLE_WORKING_DIRECTORY/.bin"
wget https://github.com/mozilla/sccache/releases/download/0.2.13/sccache-0.2.13-x86_64-unknown-linux-musl.tar.gz
tar -C "$CIRCLE_WORKING_DIRECTORY/.bin" -xvf sccache-0.2.13-x86_64-unknown-linux-musl.tar.gz
mv $CIRCLE_WORKING_DIRECTORY/.bin/sccache-0.2.13-x86_64-unknown-linux-musl/sccache $CIRCLE_WORKING_DIRECTORY/.bin/sccache
wget https://github.com/mozilla/sccache/releases/download/v0.3.0/sccache-v0.3.0-x86_64-unknown-linux-musl.tar.gz
tar -C "$CIRCLE_WORKING_DIRECTORY/.bin" -xvf sccache-v0.3.0-x86_64-unknown-linux-musl.tar.gz
mv $CIRCLE_WORKING_DIRECTORY/.bin/sccache-v0.3.0-x86_64-unknown-linux-musl/sccache $CIRCLE_WORKING_DIRECTORY/.bin/sccache
export PATH="$PATH:$CIRCLE_WORKING_DIRECTORY/.bin"
export RUSTC_WRAPPER="sccache"
rm -rf "$CIRCLE_WORKING_DIRECTORY/.cargo/registry"
sudo apt-get update && sudo apt-get install -y clang llvm-dev llvm pkg-config xz-utils make libssl-dev libssl-dev
DEBIAN_FRONTEND=noninteractive sudo apt-get update
DEBIAN_FRONTEND=noninteractive sudo apt-get dist-upgrade -y -o DPkg::Options::=--force-confold
DEBIAN_FRONTEND=noninteractive sudo apt-get install -y --no-install-recommends clang llvm-dev llvm pkg-config xz-utils make libssl-dev libssl-dev
- restore_cache:
keys:
- << parameters.cache_key >>
Expand Down Expand Up @@ -70,7 +72,7 @@ jobs:

environment:
docker:
- image: cimg/rust:1.62
- image: cimg/rust:1.63
resource_class: xlarge
parallelism: 1
steps:
Expand All @@ -85,7 +87,7 @@ jobs:

snarkos:
docker:
- image: cimg/rust:1.62
- image: cimg/rust:1.63
resource_class: xlarge
parallelism: 20
steps:
Expand All @@ -100,7 +102,7 @@ jobs:

# codecov:
# machine:
# image: ubuntu-1604:202004-01
# image: ubuntu-2204:current
# docker_layer_caching: true
# resource_class: xlarge
# steps:
Expand All @@ -116,7 +118,7 @@ jobs:

fmt:
docker:
- image: cimg/rust:1.62
- image: cimg/rust:1.63
resource_class: xlarge
steps:
- checkout
Expand All @@ -132,7 +134,7 @@ jobs:

clippy:
docker:
- image: cimg/rust:1.62
- image: cimg/rust:1.63
resource_class: xlarge
steps:
- checkout
Expand All @@ -149,28 +151,28 @@ jobs:

build-and-publish-docker-arm:
machine:
image: ubuntu-2004:202101-01
image: ubuntu-2204:current
docker_layer_caching: true
resource_class: arm.large
resource_class: arm.2xlarge
steps:
- checkout
- run: mkdir -p my_workspace
- run:
name: "Build snarkOS Docker Image ARM V8"
name: "Build snarkOS Docker image arm-v8"
no_output_timeout: 2h
command: |
VERSION=$(git rev-parse --short HEAD)
docker build -f Dockerfile -t $DOCKER_REPO:$CIRCLE_BRANCH-$VERSION-arm64 .
- run:
name: "Push snarkOS Docker Image ARM V8"
name: "Push snarkOS Docker image arm-v8"
command: |
VERSION=$(git rev-parse --short HEAD)
echo $DOCKERHUB_TOKEN | docker login -u $DOCKERHUB_USERNAME --password-stdin
# CREATE THE SHELL FILE WITH IMAGE NAME AND TAG
docker push $DOCKER_REPO:$CIRCLE_BRANCH-$VERSION-arm64
echo "Pushed $DOCKER_REPO:$CIRCLE_BRANCH-$VERSION-arm64"
- run:
name: "Save arm64 image tag"
name: "Save arm-v8 image tag"
command: |
VERSION=$(git rev-parse --short HEAD)
echo "$CIRCLE_BRANCH-$VERSION-arm64" > my_workspace/docker_tag_arm
Expand All @@ -181,20 +183,20 @@ jobs:

build-and-publish-docker-amd:
machine:
image: ubuntu-2004:202101-01
image: ubuntu-2204:current
docker_layer_caching: true
resource_class: xlarge
resource_class: 2xlarge
steps:
- checkout
- run: mkdir -p my_workspace
- run:
name: "Build snarkOS Docker Image AMD"
name: "Build snarkOS Docker image amd64"
no_output_timeout: 2h
command: |
VERSION=$(git rev-parse --short HEAD)
docker build -f Dockerfile -t $DOCKER_REPO:$CIRCLE_BRANCH-$VERSION-amd64 .
- run:
name: "Push snarkOS Docker Image AMD"
name: "Push snarkOS Docker image amd64"
command: |
VERSION=$(git rev-parse --short HEAD)
echo $DOCKERHUB_TOKEN | docker login -u $DOCKERHUB_USERNAME --password-stdin
Expand All @@ -212,9 +214,9 @@ jobs:

publish_snarkos_manifest:
machine:
image: ubuntu-2004:202101-01
image: ubuntu-2204:current
docker_layer_caching: true
resource_class: medium
resource_class: arm.2xlarge
steps:
- checkout
- attach_workspace:
Expand All @@ -233,7 +235,7 @@ jobs:
echo $AMD_TAG
docker pull $DOCKER_REPO:$AMD_TAG
- run:
name: "Create and push Docker multi arch manifest"
name: "Create and push Docker multi-arch manifests"
command: |
ARM_TAG=$(cat my_workspace/docker_tag_arm)
AMD_TAG=$(cat my_workspace/docker_tag_amd)
Expand All @@ -246,6 +248,10 @@ jobs:
docker manifest inspect $DOCKER_REPO:${CIRCLE_BRANCH}-latest
docker manifest push $DOCKER_REPO:${CIRCLE_BRANCH}-latest
echo "Pushed $DOCKER_REPO:${CIRCLE_BRANCH}-latest"
docker manifest create $DOCKER_REPO:latest --amend $DOCKER_REPO:${ARM_TAG} --amend $DOCKER_REPO:${AMD_TAG}
docker manifest inspect $DOCKER_REPO:latest
docker manifest push $DOCKER_REPO:latest
echo "Pushed $DOCKER_REPO:latest"
workflows:
main-workflow:
Expand All @@ -261,7 +267,6 @@ workflows:
when:
or:
- equal: [ testnet3, << pipeline.git.branch >> ]
- equal: [ docker-builds, << pipeline.git.branch >> ]
jobs:
- build-and-publish-docker-arm
- build-and-publish-docker-amd
Expand Down
25 changes: 18 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
FROM ubuntu:18.04 AS builder
FROM ubuntu:22.04 AS builder

ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH \
DEBIAN_FRONTEND=noninteractive

RUN set -eux ; \
apt-get update -y && \
apt-get dist-upgrade -y && \
Expand Down Expand Up @@ -38,22 +40,31 @@ RUN set -eux ; \
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*;

WORKDIR /usr/src/snarkOS

COPY . .

RUN cargo build --release
FROM ubuntu:18.04

#---
FROM ubuntu:22.04
SHELL ["/bin/bash", "-c"]

VOLUME ["/aleo/data"]

RUN set -ex && \
apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade -y -o DPkg::Options::=--force-confold && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
ca-certificates curl jq && \
ca-certificates && \
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false && \
apt-get clean && \
ln -s /aleo/data /root/.aleo && \
rm -rf /var/lib/apt/lists/* && \
mkdir -p /aleo/{bin,data} && \
mkdir /usr/local/cargo
mkdir -p /aleo/{bin,data}

COPY --from=builder /usr/src/snarkOS/target/release/snarkos /aleo/bin/
COPY --from=builder /usr/src/snarkOS/start /aleo/
CMD ["/aleo/start"]
COPY --from=builder /usr/src/snarkOS/entrypoint.sh /aleo/

CMD ["/aleo/entrypoint.sh"]
25 changes: 25 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: "3.5"

services:
client:
container_name: snarkos-client
image: aleohq/snarkos:latest
volumes:
- snarkos-client-vol:/aleo/data
build:
context: .
dockerfile: ./Dockerfile
environment:
RUST_LOG: "debug"
SNARKOS_PORT: "0.0.0.0:4133"
RPC_PORT: "0.0.0.0:3033"
LOGLEVEL: "2"
ALEO_PRIVKEY:
restart: unless-stopped
command: ["/aleo/entrypoint.sh"]
ports:
- 3033:3033
- 4133:4133

volumes:
snarkos-client-vol:
26 changes: 26 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
# running the Aleo Testnet3 client in a container

# check if environment variables are set
if [[ -z ${RUST_LOG+a} ]]; then
RUST_LOG=debug
fi

if [[ -z ${SNARKOS_PORT+a} ]]; then
SNARKOS_PORT="0.0.0.0:4133"
fi

if [[ -z ${RPC_PORT+a} ]]; then
RPC_PORT="0.0.0.0:3033"
fi

if [[ -z ${LOGLEVEL+a} ]]; then
LOGLEVEL="2"
fi

# if address is set
if [ -z ${ALEO_PRIVKEY+a} ]; then
/aleo/bin/snarkos --node ${SNARKOS_PORT} --rpc ${RPC_PORT} --verbosity ${LOGLEVEL}
else
/aleo/bin/snarkos --node ${SNARKOS_PORT} --rpc ${RPC_PORT} --verbosity ${LOGLEVEL} --private_key ${ALEO_PRIVKEY}
fi
13 changes: 13 additions & 0 deletions run-client-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
# running the Aleo Testnet3 client with Docker Compose

# USAGE examples:
# CLI : ./run-client-docker.sh

while :
do
echo "Checking for the latest snarkOS container..."
$(docker-compose pull && docker-compose --project-name aleo up -d)
# sleeping 30 minutes
sleep 1800
done

0 comments on commit 1646ed8

Please sign in to comment.