Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: build dev-node image #1

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 125 additions & 0 deletions .github/workflows/build-deploy.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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/[email protected]
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@v3
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@v3

- name: Get build artifact
uses: actions/download-artifact@v3
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 }}

5 changes: 1 addition & 4 deletions .github/workflows/cargo-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/cargo-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/cargo-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
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 }}
cancel-in-progress: true

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:
Expand Down
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]
ENTRYPOINT ["/usr/local/bin/avn-dev-node"]
58 changes: 58 additions & 0 deletions Dockerfile.local
Original file line number Diff line number Diff line change
@@ -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"]