diff --git a/.dockerignore b/.dockerignore index 913065a3..98eab17c 100644 --- a/.dockerignore +++ b/.dockerignore @@ -3,7 +3,7 @@ **/*.txt **/*.md /docker/ -!/target/release/polkadot-collator +!/target/release/parachain-template-node # dotfiles in the repo root /.* diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e64ad2ef..2db84e10 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,17 +1,33 @@ -name: Build +name: Build # Controls when the action will run. -on: [workflow_call] +on: + push: + branches: [main, dev] + pull_request: + branches: [main, dev] + workflow_dispatch: + +# Set an environment variable (that can be overriden) for the Docker Repo +env: + DOCKER_REPO: freeverseio/laos-ownership-node jobs: - build: + build_and_push: runs-on: ubuntu-22.04 steps: # Checks-out your repository under $GITHUB_WORKSPACE - - name: Checkout Code - uses: actions/checkout@v3 + - 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 + # Caching paths to speed up builds - name: Cache Paths uses: actions/cache@v3 with: @@ -21,8 +37,34 @@ jobs: ~/.cargo/registry/cache/ ~/.cargo/git/db/ target/ - key: ${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }} - + key: ${{ runner.os }}-cargo-${{ github.job }}-${{ hashFiles('**/Cargo.lock') }} + + - name: Build + run: | + cargo build --release + + # Login to Docker hub using the credentials stored in the repository secrets + - name: Log in to Docker Hub + uses: docker/login-action@v2.1.0 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_TOKEN }} + + # create Docker image and push to Docker Hub + - name: Push Docker images + uses: docker/build-push-action@v4 + with: + context: . + file: ./local.Dockerfile + push: true + tags: ${{ env.DOCKER_REPO }}:${{ github.sha }} + + lint: + runs-on: ubuntu-22.04 + steps: + # Checks-out your repository under $GITHUB_WORKSPACE + - uses: actions/checkout@v3 + - name: Install linux dependencies run: sudo apt-get install -y clang libssl-dev llvm libudev-dev protobuf-compiler @@ -30,13 +72,23 @@ jobs: run: | rustup update stable --no-self-update rustup target add wasm32-unknown-unknown + rustup component add clippy - # Build binary - - name: Build - run: cargo build --release - - - name: Upload x86_64 linux binary to workflow - uses: actions/upload-artifact@v3 + # Caching paths to speed up builds + - name: Cache Paths + uses: actions/cache@v3 with: - name: parachain-template-node - path: ${{ github.workspace }}/target/release/parachain-template-node \ No newline at end of file + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-${{ github.job }}-${{ hashFiles('**/Cargo.lock') }} + + - name: Check clippy + run: | + cargo clippy --all-targets --workspace --features runtime-benchmarks --features try-runtime + + + diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index 3d715642..00000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: Test - -# Controls when the action will run. -on: - push: - branches: '**' - -jobs: - test: - 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-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 - rustup component add clippy - - # Check the build - - name: Check Build - run: | - SKIP_WASM_BUILD=1 cargo check --release - - - name: Check clippy - run: | - cargo clippy --all-targets --workspace --features runtime-benchmarks --features try-runtime diff --git a/.github/workflows/publish.yml b/.github/workflows/release.yml similarity index 51% rename from .github/workflows/publish.yml rename to .github/workflows/release.yml index 9a0e6461..a698f137 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/release.yml @@ -1,17 +1,19 @@ -name: Publish +# 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: Build release + +# Controls when the action will run. on: # Triggers the workflow on push events for tags only push: - branches: [main, dev] tags: - - '*' - # Triggger the workflow whenever the "Build" workflow completes - workflow_run: - workflows: [Build] - types: - - completed - + - 'v*.*.*' + # Allows you to run this workflow manually from the Actions tab workflow_dispatch: @@ -22,9 +24,6 @@ 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 @@ -41,30 +40,10 @@ jobs: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_TOKEN }} - # 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/') + # Build and push images the version tag + - name: Build and push Docker images uses: docker/build-push-action@v4 with: context: . push: true - tags: | - ${{ env.DOCKER_REPO }}:${{ github.ref_name }} - - # 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.sha }} - + tags: ${{ env.DOCKER_REPO }}:${{ github.ref_name }} diff --git a/Dockerfile b/Dockerfile index 4635f16b..abaa61ae 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,30 +1,37 @@ -FROM docker.io/library/ubuntu:22.04 +# 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 -# show backtraces -ENV RUST_BACKTRACE 1 +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 # 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 9930 9333 9944 30333 30334 # Define volumes VOLUME ["/data"] -# ws_port -ENTRYPOINT ["/usr/bin/parachain-template-node"] \ No newline at end of file +# Set the entrypoint +ENTRYPOINT ["/usr/local/bin/parachain-template-node"] \ No newline at end of file diff --git a/local.Dockerfile b/local.Dockerfile new file mode 100644 index 00000000..d54154a9 --- /dev/null +++ b/local.Dockerfile @@ -0,0 +1,30 @@ +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 + +# 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 + +# Switch to user laos +USER laos + +# copy the compiled binary to the container +COPY --chown=laos:laos --chmod=774 target/release/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 9930 9333 9944 30333 30334 + +# Define volumes +VOLUME ["/data"] + +# ws_port +ENTRYPOINT ["/usr/bin/parachain-template-node"] \ No newline at end of file