Skip to content

Commit

Permalink
s3 version for caching
Browse files Browse the repository at this point in the history
  • Loading branch information
ADobrodey committed Jul 19, 2023
1 parent 4942361 commit 2e5e6f7
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 59 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
.*
**target*
doc
Dockerfile*

!target/release/cere/
!target/release/wbuild/cere-runtime/
!target/release/wbuild/cere-dev-runtime/
150 changes: 94 additions & 56 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]

- name: Cache cargo registry
uses: actions/cache@v3
continue-on-error: false
Expand All @@ -42,71 +32,119 @@ 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:
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: 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/[email protected]
#
# - 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
57 changes: 54 additions & 3 deletions Dockerfile-new
Original file line number Diff line number Diff line change
@@ -1,11 +1,62 @@
FROM phusion/baseimage:jammy-1.0.1 as builder
LABEL maintainer="[email protected]"
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="[email protected]"
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/* && \
Expand Down

0 comments on commit 2e5e6f7

Please sign in to comment.