From b3b60b6868e3f341e1a5eb989fdf4dd24e8ef504 Mon Sep 17 00:00:00 2001 From: royki Date: Tue, 25 Jul 2023 03:07:48 -0400 Subject: [PATCH 1/3] ci: build dev-node image --- .github/workflows/build-deploy.yaml | 125 ++++++++++++++++++++++++++++ .github/workflows/cargo-build.yml | 5 +- .github/workflows/cargo-check.yml | 5 +- .github/workflows/cargo-test.yml | 5 +- .github/workflows/ci.yml | 8 +- Dockerfile | 4 +- Dockerfile.local | 58 +++++++++++++ 7 files changed, 192 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/build-deploy.yaml create mode 100644 Dockerfile.local diff --git a/.github/workflows/build-deploy.yaml b/.github/workflows/build-deploy.yaml new file mode 100644 index 0000000..8ff3ded --- /dev/null +++ b/.github/workflows/build-deploy.yaml @@ -0,0 +1,125 @@ +name: Build and Deploy + +on: + push: + branches: [dev] + paths-ignore: + - 'devops/**' + +jobs: + cancel-previous: + name: 'Cancel Previous Runs' + runs-on: ubuntu-latest + timeout-minutes: 3 + steps: + - uses: styfle/cancel-workflow-action@0.11.0 + with: + access_token: ${{ github.token }} + configure: + name: Configure + runs-on: ubuntu-latest + needs: [cancel-previous] + outputs: + ENVIRONMENT: ${{ steps.configure.outputs.ENVIRONMENT }} + IMAGE_TAG: ${{ steps.configure.outputs.IMAGE_TAG }} + steps: + - uses: styfle/cancel-workflow-action@0.11.0 + with: + access_token: ${{ github.token }} + - id: configure + run: | + if [[ "${{ github.ref }}" == "refs/heads/dev" ]]; then + echo "ENVIRONMENT=dev" >> $GITHUB_OUTPUT + echo "IMAGE_TAG=$(uuidgen)" >> $GITHUB_OUTPUT + else + echo "Branch ${{ github.ref }} is not configured for deployment" + exit 1 + fi + + cargo-build: + name: Cargo Build + runs-on: ubuntu-latest + needs: [cancel-previous, configure] + environment: + name: ${{ needs.configure.outputs.ENVIRONMENT }} + timeout-minutes: 150 + steps: + - name: Remove unnecessary files + run: | + sudo rm -rf /usr/share/dotnet + sudo rm -rf "$AGENT_TOOLSDIRECTORY" + docker rmi $(docker images -aq) || true + + - name: Check out + uses: actions/checkout@v3 + + - name: Install Protoc + uses: arduino/setup-protoc@v1 + + - name: Install toolchain + uses: dtolnay/rust-toolchain@stable + with: + toolchain: nightly-2023-05-25 + components: rustfmt, clippy + target: wasm32-unknown-unknown + + - name: Set up cargo cache + uses: actions/cache@v3 + continue-on-error: false + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-release-${{ hashFiles('**/Cargo.lock') }} + + - name: Build + run: cargo build --locked --release + + - name: Save build artifact + uses: actions/upload-artifact@master + with: + name: avn-dev-node + path: target/release/avn-dev-node + + image-build: + name: Image Build + runs-on: ubuntu-latest + needs: [cancel-previous, configure, cargo-build] + environment: + name: ${{ needs.configure.outputs.ENVIRONMENT }} + steps: + - uses: actions/checkout@v2 + + - name: Get build artifact + uses: actions/download-artifact@v2 + with: + name: avn-dev-node + path: target/release/avn-dev-node + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@master + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ${{ secrets.AWS_REGION }} + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + + - name: Build & push docker images + env: + BUILD_ID: ${{ needs.configure.outputs.IMAGE_TAG }} + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + run: | + # Build and Push ewx-avn-node + docker build -t $ECR_REGISTRY/ewx-avn-node:$BUILD_ID . -f Dockerfile + docker push $ECR_REGISTRY/ewx-avn-node:$BUILD_ID + + - name: Logout of Amazon ECR + if: always() + run: docker logout ${{ steps.login-ecr.outputs.registry }} + diff --git a/.github/workflows/cargo-build.yml b/.github/workflows/cargo-build.yml index e263f40..4ac586b 100644 --- a/.github/workflows/cargo-build.yml +++ b/.github/workflows/cargo-build.yml @@ -24,14 +24,11 @@ jobs: uses: arduino/setup-protoc@v1 - name: Install toolchain - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@stable with: - profile: minimal toolchain: nightly-2023-05-25 components: rustfmt, clippy target: wasm32-unknown-unknown - override: true - default: true - name: Set up cargo cache uses: actions/cache@v3 diff --git a/.github/workflows/cargo-check.yml b/.github/workflows/cargo-check.yml index 48f4908..6c5db8b 100644 --- a/.github/workflows/cargo-check.yml +++ b/.github/workflows/cargo-check.yml @@ -21,14 +21,11 @@ jobs: uses: arduino/setup-protoc@v1 - name: Install toolchain - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@stable with: - profile: minimal toolchain: nightly-2023-05-25 components: rustfmt, clippy target: wasm32-unknown-unknown - override: true - default: true - name: Set up cargo cache uses: actions/cache@v3 diff --git a/.github/workflows/cargo-test.yml b/.github/workflows/cargo-test.yml index 8bc89f9..41e8f2c 100644 --- a/.github/workflows/cargo-test.yml +++ b/.github/workflows/cargo-test.yml @@ -21,14 +21,11 @@ jobs: uses: arduino/setup-protoc@v1 - name: Install toolchain - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@stable with: - profile: minimal toolchain: nightly-2023-05-25 components: rustfmt, clippy target: wasm32-unknown-unknown - override: true - default: true - name: Set up cargo cache uses: actions/cache@v3 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9405c80..a7ec80e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,11 +1,9 @@ on: workflow_dispatch: pull_request: - branches: - - main + branches: [main, dev] push: - branches: - - main + branches: [main, dev] concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.ref_name }} @@ -13,10 +11,10 @@ concurrency: jobs: check-code: - if: github.ref != 'refs/heads/main' uses: ./.github/workflows/cargo-check.yml build-code: + if: github.ref != 'refs/heads/dev' uses: ./.github/workflows/cargo-build.yml test-code: diff --git a/Dockerfile b/Dockerfile index 31c6bd9..568f8af 100644 --- a/Dockerfile +++ b/Dockerfile @@ -38,6 +38,8 @@ RUN apt-get update && \ # add avn-dev-node binary to the docker image COPY target/release/avn-dev-node /usr/local/bin/ +RUN chmod +x /usr/local/bin/avn-dev-node + USER avn-node # check if executable works in this container @@ -46,4 +48,4 @@ RUN /usr/local/bin/avn-dev-node --version EXPOSE 30333 30334 9933 9944 9615 VOLUME ["/data"] -ENTRYPOINT ["/usr/local/bin/avn-dev-node"] \ No newline at end of file +ENTRYPOINT ["/usr/local/bin/avn-dev-node"] diff --git a/Dockerfile.local b/Dockerfile.local new file mode 100644 index 0000000..23f61c9 --- /dev/null +++ b/Dockerfile.local @@ -0,0 +1,58 @@ +FROM rust:latest as builder + +RUN apt update +RUN apt install -y clang cmake protobuf-compiler + +RUN rustup update nightly +RUN rustup target add wasm32-unknown-unknown --toolchain nightly +RUN rustup default nightly + +WORKDIR /var/www/ewx-avn-node +ENV CARGO_HOME=/var/www/ewx-avn-node/.cargo + +COPY . /var/www/ewx-avn-node + +ENV RUST_BACKTRACE 1 + +# Github action error - https://substrate.stackexchange.com/questions/9209/how-to-resolve-errore0422-cannot-find-struct-variant-or-union-type-linecol +# RUN cargo update + +RUN cargo build --release + +FROM ubuntu:22.04 + +# show backtraces +ENV RUST_BACKTRACE 1 + +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y \ + libssl3 \ + ca-certificates \ + curl \ + jq && \ + # apt cleanup + apt-get autoremove -y && \ + apt-get clean && \ + find /var/lib/apt/lists/ -type f -not -name lock -delete; \ + # add user and link ~/.local/share/avn-node to /data + useradd -m -u 1000 -U -s /bin/sh -d /avn-node avn-node && \ + mkdir -p /data /avn-node/.local/share && \ + chown -R avn-node:avn-node /data && \ + ln -s /data /avn-node/.local/share/avn-node && \ + mkdir -p /specs + +COPY --from=builder /var/www/ewx-avn-node/target/release/avn-dev-node /usr/local/bin/ + +# add avn-dev-node binary to the docker image +RUN chmod +x /usr/local/bin/avn-dev-node + +USER avn-node + +# check if executable works in this container +RUN /usr/local/bin/avn-dev-node --version + +EXPOSE 30333 9933 9944 9615 + +VOLUME ["/data"] + +ENTRYPOINT ["/usr/local/bin/avn-dev-node"] From c44c801a13914f8793629a8f4efeff03f38b6d21 Mon Sep 17 00:00:00 2001 From: royki Date: Tue, 25 Jul 2023 03:46:19 -0400 Subject: [PATCH 2/3] ci: small fix of v --- .github/workflows/build-deploy.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-deploy.yaml b/.github/workflows/build-deploy.yaml index 8ff3ded..3ee9cd0 100644 --- a/.github/workflows/build-deploy.yaml +++ b/.github/workflows/build-deploy.yaml @@ -79,7 +79,7 @@ jobs: run: cargo build --locked --release - name: Save build artifact - uses: actions/upload-artifact@master + uses: actions/upload-artifact@v3 with: name: avn-dev-node path: target/release/avn-dev-node @@ -91,10 +91,10 @@ jobs: environment: name: ${{ needs.configure.outputs.ENVIRONMENT }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Get build artifact - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v3 with: name: avn-dev-node path: target/release/avn-dev-node From 7bf58c9fa68734a2a9cc81fa5c7a9e4209221a73 Mon Sep 17 00:00:00 2001 From: royki Date: Tue, 25 Jul 2023 07:45:53 -0400 Subject: [PATCH 3/3] ci: rename yaml to ymll --- .github/workflows/{build-deploy.yaml => build-deploy.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{build-deploy.yaml => build-deploy.yml} (100%) diff --git a/.github/workflows/build-deploy.yaml b/.github/workflows/build-deploy.yml similarity index 100% rename from .github/workflows/build-deploy.yaml rename to .github/workflows/build-deploy.yml