Skip to content

Commit

Permalink
Remove cargo-chef (#660)
Browse files Browse the repository at this point in the history
* remove cargo-chef

* loose time limit

* global args

* introduce args in stages

* wrong positional parameter

* simplify docker build
  • Loading branch information
Kailai-Wang authored Jun 27, 2022
1 parent 7298a1f commit 61c2cb2
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 107 deletions.
30 changes: 8 additions & 22 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
- 'pallets/**'
- 'primitives/**'
- 'runtime/**'
- 'docker/Dockerfile.dev'
- 'docker/Dockerfile'
- '**/Cargo.lock'
- '**/Cargo.toml'
- '**/rust-toolchain.toml'
Expand Down Expand Up @@ -99,35 +99,21 @@ jobs:
with:
fetch-depth: 0

- name: Setup docker buildx
uses: docker/setup-buildx-action@v1

# Syncing GHA cache seems to be very slow, we use local cache for a self-hosted runner
- name: Build docker image
timeout-minutes: 60
if: needs.check-file-change.outputs.src == 'true'
uses: docker/build-push-action@v2
with:
context: .
tags: litentry/litentry-parachain:latest
outputs: type=docker,dest=litentry-parachain.tar
push: false
file: docker/Dockerfile.dev
cache-from: type=local,src=/tmp/parachain-buildx-cache
cache-to: type=local,dest=/tmp/parachain-buildx-cache-new,mode=max

- name: Move cache
if: needs.check-file-change.outputs.src == 'true'
# Temp fix for constantly growing cache, see
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
run: |
rm -rf /tmp/parachain-buildx-cache
mv /tmp/parachain-buildx-cache-new /tmp/parachain-buildx-cache
./scripts/build-docker.sh dev
echo "============================="
docker images
- name: Pull docker image optinally
if: needs.check-file-change.outputs.src == 'false'
run: |
docker pull litentry/litentry-parachain:latest
- name: Save docker image
run: |
docker save litentry/litentry-parachain:latest -o litentry-parachain.tar
- name: Upload docker image
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ inherits = "release"
[profile.production]
inherits = "release"
lto = true
codegen-units = 1
codegen-units = 1
strip = "symbols"
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ srtool-build-wasm-rococo:
srtool-build-wasm-moonbase:
@./scripts/build-wasm.sh moonbase

.PHONY: build-docker-dev ## Build docker image using Dockerfile.dev
.PHONY: build-docker-dev ## Build docker image using dev setting (--profile release)
build-docker-dev:
@./scripts/build-docker.sh dev

.PHONY: build-docker-prod ## Build docker image using Dockerfile.prod
.PHONY: build-docker-prod ## Build docker image using prod setting (--profile production)
build-docker-prod:
@./scripts/build-docker.sh prod

Expand Down
22 changes: 11 additions & 11 deletions docker/Dockerfile.prod → docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# global args that are used across multiple stages
ARG PROFILE

# ==========================
# stage 1: build
# https://hub.docker.com/_/rust
Expand All @@ -7,26 +10,23 @@ FROM rust:latest as builder
WORKDIR /litentry
COPY . /litentry

# always use the toolchain in base image
# we do not fix toolchain version as it's still evolving rapidly
RUN rustup default nightly && \
rustup target add wasm32-unknown-unknown --toolchain nightly

RUN apt-get update && \
apt-get dist-upgrade -y -o Dpkg::Options::="--force-confold" && \
apt-get install -y cmake pkg-config libssl-dev git clang libclang-dev
apt-get upgrade -y && \
apt-get install -yq openssl clang libclang-dev

ARG BUILD_ARGS
RUN cargo build --locked --profile production $BUILD_ARGS
RUN strip target/production/litentry-collator
ARG PROFILE
RUN cargo build --locked --profile $PROFILE $BUILD_ARGS

# ==========================
# stage 2: packaging
# ==========================
FROM ubuntu:20.04
LABEL maintainer="litentry-dev"

COPY --from=builder /litentry/target/production/litentry-collator /usr/local/bin
ARG PROFILE

COPY --from=builder /litentry/target/$PROFILE/litentry-collator /usr/local/bin

RUN useradd -m -u 1000 -U -s /bin/sh -d /litentry litentry && \
mkdir -p /data /litentry/.local/share && \
Expand All @@ -42,4 +42,4 @@ EXPOSE 30333 9933 9944 9615
VOLUME ["/data"]

ENTRYPOINT ["/usr/local/bin/litentry-collator"]
CMD ["--help"]
CMD ["--help"]
64 changes: 0 additions & 64 deletions docker/Dockerfile.dev

This file was deleted.

5 changes: 3 additions & 2 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[toolchain]
channel = "nightly-2022-04-01"
targets = ["wasm32-unknown-unknown"]
profile = "default" # include rustfmt, clippy
components = [ "rustfmt", "clippy" ]
targets = [ "wasm32-unknown-unknown" ]
profile = "minimal"
15 changes: 10 additions & 5 deletions scripts/build-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ ARGS="$3"
NOCACHE_FLAG=

case "$TYPE" in
dev) ;;
prod) NOCACHE_FLAG="--no-cache" ;;
*) usage; exit 1 ;;
dev)
PROFILE=release ;;
prod)
PROFILE=production
NOCACHE_FLAG="--no-cache" ;;
*)
usage; exit 1 ;;
esac

if [ -z "$TAG" ]; then
Expand All @@ -45,12 +49,13 @@ GITREPO=litentry-parachain
# Build the image
echo "------------------------------------------------------------"
echo "Building ${GITUSER}/${GITREPO}:${TAG} docker image ..."
docker build --rm ${NOCACHE_FLAG} --pull -f ./docker/Dockerfile.${TYPE} \
docker build ${NOCACHE_FLAG} --pull -f ./docker/Dockerfile \
--build-arg PROFILE="$PROFILE" \
--build-arg BUILD_ARGS="$ARGS" \
-t ${GITUSER}/${GITREPO}:${TAG} .

# Tag it with latest if no tag parameter was provided
[ -z "$1" ] && docker tag ${GITUSER}/${GITREPO}:${TAG} ${GITUSER}/${GITREPO}:latest
[ -z "$2" ] && docker tag ${GITUSER}/${GITREPO}:${TAG} ${GITUSER}/${GITREPO}:latest

# Show the list of available images for this repo
echo "Image is ready"
Expand Down

0 comments on commit 61c2cb2

Please sign in to comment.