Skip to content
This repository was archived by the owner on Oct 2, 2023. It is now read-only.
42 changes: 42 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Build

# Controls when the action will run.
on: [workflow_call]

jobs:
build:
runs-on: ubuntu-22.04
steps:
# Checks-out your repository under $GITHUB_WORKSPACE
- name: Checkout Code
uses: actions/checkout@v3

# Caching paths to speed up builds
- name: Cache Paths
uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}

- name: Install linux dependencies
run: sudo apt-get install -y clang libssl-dev llvm libudev-dev protobuf-compiler

- name: Install Rust
run: |
rustup update stable --no-self-update
rustup target add wasm32-unknown-unknown

# Build binary
- name: Build
run: cargo build --release

- name: Upload x86_64 linux binary to workflow
uses: actions/upload-artifact@v3
with:
name: parachain-template-node
path: ${{ github.workspace }}/target/release/parachain-template-node
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
# This is an example GitHub action that will build and publish a Docker image to DockerHub
# You need to add the following secrets to your GitHub Repository or Organization to make this work
# - DOCKER_USERNAME: The username of the DockerHub account. E.g. parity
# - DOCKER_TOKEN: Access token for DockerHub, see https://docs.docker.com/docker-hub/access-tokens/. E.g. VVVVVVVV-WWWW-XXXXXX-YYYY-ZZZZZZZZZ
# The following are setup as an environment variable below
# - DOCKER_REPO: The unique name of the DockerHub repository. E.g. parity/polkadot
name: Publish

name: Build & Publish Docker Image

# Controls when the action will run.
on:
# Triggers the workflow on push events for tags only
push:
branches: [main, dev]
tags:
# Catches v1.2.3 and v1.2.3-rc1
- v[0-9]+.[0-9]+.[0-9]+*

- '*'
# Triggger the workflow whenever the "Build" workflow completes
workflow_run:
workflows: [Build]
types:
- completed

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

Expand All @@ -25,6 +22,9 @@ env:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
build:
uses: ./.github/workflows/build.yml
publish:
needs: build
# The type of runner that the job will run on
runs-on: ubuntu-22.04

Expand All @@ -41,12 +41,30 @@ jobs:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}

# Build and push images the version tag
- name: Build and push Docker images
# Download the binary from the previous workflow
- name: Download x86_64 linux binary
uses: actions/download-artifact@v3
with:
name: parachain-template-node
path: ${{ github.workspace }}

# Publish image version tag
- name: Publish docker image using tag
if: startsWith(github.event.ref, 'refs/tags/')
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: |
${{ env.DOCKER_REPO }}:${{ github.ref_name }}
${{ env.DOCKER_REPO }}:latest

# Publish image version sha
- name: Publish docker image using commit sha
if: startsWith(github.event.ref, 'refs/heads/')
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: |
${{ env.DOCKER_REPO }}:${{ github.ref_sha }}

35 changes: 15 additions & 20 deletions .github/workflows/check.yml → .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
name: Check Set-Up, Build & Tests
name: Test

# Controls when the action will run.
on:
push:
branches: [main, dev]
pull_request:
branches: [main, dev]
workflow_dispatch:
branches: '**'

jobs:
check:
test:
runs-on: ubuntu-22.04
steps:
# Checks-out your repository under $GITHUB_WORKSPACE
- name: Checkout Code
uses: actions/checkout@v3

- name: Install linux dependencies
run: sudo apt-get install -y clang libssl-dev llvm libudev-dev protobuf-compiler

- name: Install Rust
run: |
rustup update stable --no-self-update
rustup target add wasm32-unknown-unknown

# Caching paths to speed up builds
- name: Cache Paths
uses: actions/cache@v3
Expand All @@ -34,15 +23,21 @@ jobs:
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
key: ${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.lock') }}

- name: Install linux dependencies
run: sudo apt-get install -y clang libssl-dev llvm libudev-dev protobuf-compiler

- name: Install Rust
run: |
rustup update stable --no-self-update
rustup target add wasm32-unknown-unknown

# Check the build
- name: Check Build
run: |
SKIP_WASM_BUILD=1 cargo check --release

# Check the build for benchmarking
- name: Check Build for Benchmarking
run: >
pushd node &&
cargo check --features=runtime-benchmarks --release
# Test code
- name: Test
run: cargo test
31 changes: 12 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,37 +1,30 @@
# This is the build stage for laos. Here we create the binary in a temporary image.
FROM docker.io/paritytech/ci-linux:production as builder

WORKDIR /laos
COPY . /laos

RUN rustup target add wasm32-unknown-unknown --toolchain nightly
RUN cargo build --locked --release

# This is the 2nd stage: a very small image where we copy the laos binary."
FROM docker.io/library/ubuntu:22.04

# show backtraces
ENV RUST_BACKTRACE 1

# Create user
RUN useradd -m -u 1000 -U -s /bin/sh -d /laos laos

# Copy binary from builder
COPY --from=builder /laos/target/release/parachain-template-node /usr/local/bin

# Set up directories and permissions
RUN mkdir -p /data /laos/.local/share && \
chown -R laos:laos /data /laos/.local/share && \
ln -s /data /laos/.local/share/laos

# Check if executable works in this container
RUN su laos -c '/usr/local/bin/parachain-template-node --version'

# Switch to user laos
USER laos

# copy the compiled binary to the container
COPY --chown=laos:laos --chmod=774 parachain-template-node /usr/bin/parachain-template-node

# check if executable works in this container
RUN /usr/bin/parachain-template-node --version

# Expose necessary ports
EXPOSE 30333 9933 9944 9615
EXPOSE 9930 9333 9944 30333 30334

# Define volumes
VOLUME ["/data"]

# Set the entrypoint
ENTRYPOINT ["/usr/local/bin/parachain-template-node"]
# ws_port
ENTRYPOINT ["/usr/bin/parachain-template-node"]