diff --git a/.dockerignore b/.dockerignore index 1856e17ca..b73ef56af 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,8 @@ .* +**target* doc Dockerfile* + +!target/release/cere/ +!target/release/wbuild/cere-runtime/ +!target/release/wbuild/cere-dev-runtime/ diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index c1d77e9f3..fa9608ea7 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -22,16 +22,6 @@ jobs: id-token: write steps: - uses: actions/checkout@v3 - - uses: actions-rs/toolchain@v1 - with: - toolchain: nightly-2022-10-09 - profile: minimal - override: true - components: rustfmt, clippy - - - name: Run sccache-cache - uses: mozilla-actions/sccache-action@v0.0.3 - - name: Cache cargo registry uses: actions/cache@v3 continue-on-error: false @@ -42,33 +32,6 @@ jobs: key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} restore-keys: | ${{ runner.os }}-cargo- - - - name: Save sccache - uses: actions/cache@v2 - continue-on-error: false - with: - path: ${{ env.SCCACHE_DIR }} - key: ${{ runner.os }}-sccache-${{ hashFiles('**/Cargo.lock') }} - restore-keys: | - ${{ runner.os }}-sccache- - - - name: Lint - run: cargo fmt --all -- --check - - - name: Install Protoc - uses: arduino/setup-protoc@v1 - with: - version: "3.15.8" - - - name: Start sccache server - run: sccache --start-server - - - name: Build - run: cargo build --release - - - name: Stop sccache server - run: sccache --stop-server || true - - name: configure aws credentials uses: aws-actions/configure-aws-credentials@v2 with: @@ -76,37 +39,112 @@ jobs: role-session-name: ${{ github.event.repository.name }} aws-region: us-west-2 + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + - name: Get short SHA run: | echo GITHUB_SHA=${GITHUB_SHA:0:7} >> $GITHUB_ENV - # DEBUG - ls -la target/release - ls -la target/release/wbuild - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 - - name: Login to Amazon ECR - id: login-ecr - uses: aws-actions/amazon-ecr-login@v1 + - name: Build and push docker image to ECR uses: docker/build-push-action@v4 with: context: . file: ./Dockerfile-new push: true + build-args: | + AWS_ACCESS_KEY_ID=${{ env.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY=${{ env.AWS_ACCESS_KEY_ID }} + AWS_SESSION_TOKEN=${{ env.AWS_ACCESS_KEY_ID }} tags: | ${{ steps.login-ecr.outputs.registry }}/pos-network-node:${{ github.sha }} ${{ steps.login-ecr.outputs.registry }}/pos-network-node:dev-latest - - name: Upload cere-runtime wasm artifact - uses: actions/upload-artifact@v3 - with: - name: cere_runtime.compact.compressed.${{ env.GITHUB_SHA }}.wasm - path: target/${{ vars.PROFILE }}/wbuild/cere-runtime/cere_runtime.compact.compressed.wasm - - - name: Upload cere-dev-runtime wasm artifact - uses: actions/upload-artifact@v3 - with: - name: cere_dev_runtime.compact.compressed.${{ env.GITHUB_SHA }}.wasm - path: target/${{ vars.PROFILE }}/wbuild/cere-dev-runtime/cere_dev_runtime.compact.compressed.wasm +# - uses: actions-rs/toolchain@v1 +# with: +# toolchain: nightly-2022-10-09 +# profile: minimal +# override: true +# components: rustfmt, clippy +# +# - name: Run sccache-cache +# uses: mozilla-actions/sccache-action@v0.0.3 +# +# - name: Cache cargo registry +# uses: actions/cache@v3 +# continue-on-error: false +# with: +# path: | +# ~/.cargo/registry +# ~/.cargo/git +# key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} +# restore-keys: | +# ${{ runner.os }}-cargo- +# +# - name: Save sccache +# uses: actions/cache@v2 +# continue-on-error: false +# with: +# path: ${{ env.SCCACHE_DIR }} +# key: ${{ runner.os }}-sccache-${{ hashFiles('**/Cargo.lock') }} +# restore-keys: | +# ${{ runner.os }}-sccache- +# +# - name: Lint +# run: cargo fmt --all -- --check +# +# - name: Install Protoc +# uses: arduino/setup-protoc@v1 +# with: +# version: "3.15.8" +# +# - name: Start sccache server +# run: sccache --start-server +# +# - name: Build +# run: cargo build --release +# +# - name: Stop sccache server +# run: sccache --stop-server || true +# +# - name: configure aws credentials +# uses: aws-actions/configure-aws-credentials@v2 +# with: +# role-to-assume: arn:aws:iam::${{ vars.DEV_NETWORK_AWS_ACCOUNT_ID }}:role/github +# role-session-name: ${{ github.event.repository.name }} +# aws-region: us-west-2 +# +# - name: Get short SHA +# run: | +# echo GITHUB_SHA=${GITHUB_SHA:0:7} >> $GITHUB_ENV +# +# - name: Set up Docker Buildx +# uses: docker/setup-buildx-action@v2 +# - name: Login to Amazon ECR +# id: login-ecr +# uses: aws-actions/amazon-ecr-login@v1 +# - name: Build and push docker image to ECR +# uses: docker/build-push-action@v4 +# with: +# context: . +# file: ./Dockerfile-new +# push: true +# tags: | +# ${{ steps.login-ecr.outputs.registry }}/pos-network-node:${{ github.sha }} +# ${{ steps.login-ecr.outputs.registry }}/pos-network-node:dev-latest +# +# - name: Upload cere-runtime wasm artifact +# uses: actions/upload-artifact@v3 +# with: +# name: cere_runtime.compact.compressed.${{ env.GITHUB_SHA }}.wasm +# path: target/${{ vars.PROFILE }}/wbuild/cere-runtime/cere_runtime.compact.compressed.wasm +# +# - name: Upload cere-dev-runtime wasm artifact +# uses: actions/upload-artifact@v3 +# with: +# name: cere_dev_runtime.compact.compressed.${{ env.GITHUB_SHA }}.wasm +# path: target/${{ vars.PROFILE }}/wbuild/cere-dev-runtime/cere_dev_runtime.compact.compressed.wasm diff --git a/Dockerfile-new b/Dockerfile-new index 3385c7bc1..6b592c808 100644 --- a/Dockerfile-new +++ b/Dockerfile-new @@ -1,11 +1,62 @@ +FROM phusion/baseimage:jammy-1.0.1 as builder +LABEL maintainer="team@cere.network" +LABEL description="This is the build stage to create the binary." +ARG PROFILE=release +WORKDIR /cerenetwork +COPY . /cerenetwork + +RUN apt-get update && \ + apt-get install -y \ + clang \ + cmake \ + git \ + libpq-dev \ + libssl-dev \ + pkg-config \ + unzip \ + wget + +# Configure sccache +ENV SCCACHE_VERSION=0.5.4 +RUN wget https://github.com/mozilla/sccache/releases/download/v${SCCACHE_VERSION}/sccache-v${SCCACHE_VERSION}-x86_64-unknown-linux-musl.tar.gz \ + -O - | tar -xz \ + && mv sccache-v${SCCACHE_VERSION}-x86_64-unknown-linux-musl/sccache /usr/local/bin/sccache \ + && chmod +x /usr/local/bin/sccache \ + && rm -rf sccache-v${SCCACHE_VERSION}-x86_64-unknown-linux-musl +ENV RUSTC_WRAPPER=/usr/local/bin/sccache +ENV SCCACHE_BUCKET=cere-blockchain-sccache +ENV SCCACHE_REGION=us-west-2 +ENV SCCACHE_S3_USE_SSL=true + +ARG AWS_ACCESS_KEY_ID +ARG AWS_SECRET_ACCESS_KEY +ARG AWS_SESSION_TOKEN + +# Installation script is taken from https://grpc.io/docs/protoc-installation/ +ENV PROTOC_VERSION=3.15.8 +RUN PB_REL="https://github.com/protocolbuffers/protobuf/releases" && \ + curl -LO $PB_REL/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip && \ + mkdir -p /usr/local/protoc && \ + unzip protoc-${PROTOC_VERSION}-linux-x86_64.zip -d /usr/local/protoc && \ + chmod +x /usr/local/protoc/bin/protoc && \ + ln -s /usr/local/protoc/bin/protoc /usr/local/bin + +RUN curl https://sh.rustup.rs -sSf | sh -s -- -y && \ + export PATH=$PATH:$HOME/.cargo/bin && \ + scripts/init.sh && \ + AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \ + AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \ + AWS_SESSION_TOKEN=$AWS_SESSION_TOKEN \ + cargo build --$PROFILE + FROM phusion/baseimage:0.11 LABEL maintainer="team@cere.network" LABEL description="This is the optimization to create a small image." ARG PROFILE=release -COPY ./target/$PROFILE/cere /usr/local/bin -COPY ./target/$PROFILE/wbuild/cere-runtime /home/cere/cere-runtime-artifacts -COPY ./target/$PROFILE/wbuild/cere-dev-runtime /home/cere/cere-dev-runtime-artifacts +COPY --from=builder /cerenetwork/target/$PROFILE/cere /usr/local/bin +COPY --from=builder /cerenetwork/target/$PROFILE/wbuild/cere-runtime /home/cere/cere-runtime-artifacts +COPY --from=builder /cerenetwork/target/$PROFILE/wbuild/cere-dev-runtime /home/cere/cere-dev-runtime-artifacts RUN mv /usr/share/ca* /tmp && \ rm -rf /usr/share/* && \