diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index df8ddb4..17fd1c7 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -5,15 +5,13 @@ on: # schedule: # - cron: '22 3 * * *' push: - branches: [ main, 'docker-publish*', 'v0.10*' ] + branches: [ main, 'v0.10*' ] # Publish semver tags as releases. tags: [ 'v*.*.*' ] - pull_request: - branches: [ main ] env: # Use docker.io for Docker Hub if empty - REGISTRY: ${{ github.repository_owner != 'nervosnetwork' && 'ghcr.io/' || '' }} + REGISTRY: ${{ github.ref_type != 'tag' && 'ghcr.io/' || '' }} # github.repository as / IMAGE_NAME: godwoken-prebuilds @@ -21,22 +19,30 @@ env: jobs: docker-build-push: runs-on: ubuntu-latest + # Map the meta step outputs to this job outputs + outputs: + image_name: ${{ steps.result.outputs.image_name }} + image_tag: ${{ steps.result.outputs.image_tag }} + # If you specify the access for any of these scopes, all of those that are not specified are set to none. permissions: contents: read packages: write steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 - - uses: actions/cache@v2 + - uses: actions/cache@v3 with: path: | - ~/.cargo/registry - ~/.cargo/git - ~/.cargo/bin - target - key: ${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }} + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-cargo- - name: Install Rust components run: rustup component add rustfmt && rustup component add clippy @@ -56,14 +62,82 @@ jobs: # Login against a Docker registry except on PR # https://github.com/docker/login-action - # The GHP_CRT secret is password or personal access token with `write:packages` access scope + # GitHub automatically creates a unique GITHUB_TOKEN secret to use in this workflow. - name: Log into registry ${{ env.REGISTRY }} if: github.event_name != 'pull_request' uses: docker/login-action@v1 with: registry: ${{ env.REGISTRY }} - username: ${{ secrets.DOCKERHUB_USERNAME || github.actor }} - password: ${{ secrets.DOCKERHUB_TOKEN || secrets.GHP_CRT }} + username: ${{ github.ref_type != 'tag' && github.repository_owner || secrets.DOCKERHUB_USERNAME }} + password: ${{ github.ref_type != 'tag' && secrets.GITHUB_TOKEN || secrets.DOCKERHUB_TOKEN }} + + - name: Prepare components + id: prepare + run: | + make prepare-repos + echo "Record the component's reference to the outputs of this step" + cat versions + + - name: Print the references of components + run: | + echo ref.component.godwoken=${{ steps.prepare.outputs.GODWOKEN_REF }} + echo ref.component.godwoken-scripts=${{ steps.prepare.outputs.GODWOKEN_SCRIPTS_REF }} + echo ref.component.godwoken-polyjuice=${{ steps.prepare.outputs.POLYJUICE_REF }} + echo ref.component.clerkb=${{ steps.prepare.outputs.CLERKB_REF }} + + - name: Cache of component.clerkb + id: clerkb-cache + uses: actions/cache@v3 + with: + path: | + build/clerkb/build/debug/poa + build/clerkb/build/debug/state + key: component.clerkb-${{ steps.prepare.outputs.clerkb-sha1 }} + - name: Build clerkb + if: steps.clerkb-cache.outputs.cache-hit != 'true' + working-directory: build/clerkb + run: yarn && make all-via-docker + + - name: Cache of component.godwoken-scripts + id: godwoken-scripts-cache + uses: actions/cache@v3 + with: + path: | + build/godwoken-scripts/build/release/* + build/godwoken-scripts/c/build/*-generator + build/godwoken-scripts/c/build/*-validator + build/godwoken-scripts/c/build/account_locks/* + key: component.godwoken-scripts-${{ steps.prepare.outputs.godwoken-scripts-sha1 }} + - name: Build godwoken-scripts + if: steps.godwoken-scripts-cache.outputs.cache-hit != 'true' + working-directory: build/godwoken-scripts + run: cd c && make && cd .. && capsule build --release --debug-output + + - name: Cache of component.godwoken-polyjuice + id: godwoken-polyjuice-cache + uses: actions/cache@v3 + with: + path: | + build/godwoken-polyjuice/build/*generator* + build/godwoken-polyjuice/build/*validator* + key: component.godwoken-polyjuice-${{ steps.prepare.outputs.godwoken-polyjuice-sha1 }} + - name: Build godwoken-polyjuice + if: steps.godwoken-polyjuice-cache.outputs.cache-hit != 'true' + working-directory: build/godwoken-polyjuice + run: make all-via-docker + + - name: Cache of component.godwoken + id: godwoken-cache + uses: actions/cache@v3 + with: + path: | + build/godwoken/target/release/godwoken + build/godwoken/target/release/gw-tools + key: component.godwoken-${{ steps.prepare.outputs.godwoken-sha1 }} + - name: Build godwoken + if: steps.godwoken-cache.outputs.cache-hit != 'true' + working-directory: build/godwoken + run: rustup component add rustfmt && CARGO_PROFILE_RELEASE_LTO=true cargo build --release # Extract metadata (tags, labels) for Docker # https://github.com/docker/metadata-action @@ -71,18 +145,37 @@ jobs: id: meta uses: docker/metadata-action@v3 with: - images: ${{ env.REGISTRY }}${{ github.repository_owner == 'nervosnetwork' && 'nervos' || github.repository_owner }}/${{ env.IMAGE_NAME }} + images: ${{ env.REGISTRY }}${{ startsWith(github.ref, 'refs/tags') && github.repository_owner == 'nervosnetwork' && 'nervos' || github.repository_owner }}/${{ env.IMAGE_NAME }} + # dynamically set date as a suffix + tags: | + type=ref,event=tag + type=ref,event=branch,suffix=-{{date 'YYYYMMDDHHmm'}} + type=ref,event=branch + labels: | + maintainer=Nervos Core Dev + org.opencontainers.image.authors=Nervos Core Dev + source.component.godwoken=https://github.com/nervosnetwork/godwoken + source.component.godwoken-scripts-Scripts=https://github.com/nervosnetwork/godwoken-scripts + source.component.godwoken-polyjuice=https://github.com/nervosnetwork/godwoken-polyjuice + source.component.clerkb=https://github.com/nervosnetwork/clerkb.git + ref.component.godwoken=${{ steps.prepare.outputs.GODWOKEN_REF }} + ref.component.godwoken-sha1=${{ steps.prepare.outputs.godwoken-sha1 }} + ref.component.godwoken-scripts=${{ steps.prepare.outputs.GODWOKEN_SCRIPTS_REF }} + ref.component.godwoken-scripts-sha1=${{ steps.prepare.outputs.godwoken-scripts-sha1 }} + ref.component.godwoken-polyjuice=${{ steps.prepare.outputs.POLYJUICE_REF }} + ref.component.godwoken-polyjuice-sha1=${{ steps.prepare.outputs.godwoken-polyjuice-sha1 }} - - name: build - run: make build-components + ref.component.clerkb=${{ steps.prepare.outputs.OMNI_LOCK_REF }} + ref.component.clerkb-sha1=${{ steps.prepare.outputs.clerkb-sha1 }} # Build and push Docker image with Buildx (don't push on PR) # https://github.com/docker/build-push-action - name: Build and push Docker image to ${{ env.REGISTRY }}${{ github.repository_owner }}/${{ env.IMAGE_NAME }} - if: ${{ github.repository_owner != 'nervosnetwork'}} + if: ${{ github.ref_type != 'tag' }} uses: docker/build-push-action@v2 with: context: . + file: Dockerfile.fast push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} @@ -94,17 +187,33 @@ jobs: uses: docker/build-push-action@v2 with: context: . + file: Dockerfile.fast push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - # - name: Check versions of the binaries used by Godwoken - # run: | - # FIXME: /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.29' not found (required by godwoken) - # docker run --rm godwoken-prebuilds godwoken --version - # docker run --rm godwoken-prebuilds gw-tools --version - ### - # docker run --rm godwoken-prebuilds ckb --version - # docker run --rm godwoken-prebuilds ckb-cli --version - # docker run --rm godwoken-prebuilds ckb-indexer --version - # docker run --rm godwoken-prebuilds find /scripts + - name: Check versions of the binaries in ${{ fromJSON(steps.meta.outputs.json).tags[0] }} + if: ${{ github.event_name != 'pull_request' }} + env: + IMAGE: ${{ fromJSON(steps.meta.outputs.json).tags[0] }} + run: | + docker run --rm ${{ env.IMAGE }} godwoken --version + docker run --rm ${{ env.IMAGE }} gw-tools --version + docker run --rm ${{ env.IMAGE }} ckb --version + docker run --rm ${{ env.IMAGE }} ckb-cli --version + docker run --rm ${{ env.IMAGE }} ckb-indexer --version + docker run --rm ${{ env.IMAGE }} find /scripts -type f -exec sha1sum {} \; + + - name: Record image info to the outputs of this jobs + id: result + run: | + echo "::set-output name=image_name::`echo ${{ fromJSON(steps.meta.outputs.json).tags[0] }} | awk -F ':' '{print $1}'`" + echo "::set-output name=image_tag::`echo ${{ fromJSON(steps.meta.outputs.json).tags[0] }} | awk -F ':' '{print $NF}'`" + + integration-test: + needs: docker-build-push + uses: nervosnetwork/godwoken-tests/.github/workflows/reusable-integration-test-v0.yml@develop + with: + gw_prebuild_image_name: ${{ needs.docker-build-push.outputs.image_name }} + gw_prebuild_image_tag: ${{ needs.docker-build-push.outputs.image_tag }} + # gw_prebuild_image_digest: ${{ needs.docker-build-push.outputs.image_digest }} diff --git a/Dockerfile.fast b/Dockerfile.fast new file mode 100644 index 0000000..930a99a --- /dev/null +++ b/Dockerfile.fast @@ -0,0 +1,48 @@ +FROM ubuntu:21.04 + +RUN mkdir -p /scripts/godwoken-scripts \ + && mkdir -p /scripts/godwoken-polyjuice \ + && mkdir -p /scripts/clerkb \ + && mkdir /ckb \ + && mkdir /ckb-indexer + +RUN apt-get update \ + && apt-get dist-upgrade -y \ + && apt-get install -y curl unzip \ + && apt-get clean \ + && echo 'Finished installing OS updates' + +# ckb +RUN cd /ckb \ + && curl -LO https://github.com/nervosnetwork/ckb/releases/download/v0.101.7/ckb_v0.101.7_x86_64-unknown-linux-gnu.tar.gz \ + && tar xzf ckb_v0.101.7_x86_64-unknown-linux-gnu.tar.gz \ + && cp ckb_v0.101.7_x86_64-unknown-linux-gnu/ckb /bin/ckb \ + && cp ckb_v0.101.7_x86_64-unknown-linux-gnu/ckb-cli /bin/ckb-cli \ + && rm -rf /ckb + +# ckb-indexer +RUN cd /ckb-indexer \ + && curl -LO https://github.com/nervosnetwork/ckb-indexer/releases/download/v0.3.2/ckb-indexer-0.3.2-linux.zip \ + && unzip ckb-indexer-0.3.2-linux.zip && tar xzf ckb-indexer-linux-x86_64.tar.gz \ + && cp /ckb-indexer/ckb-indexer /bin/ckb-indexer \ + && rm -rf /ckb-indexer + +# /scripts/clerkb +COPY build/clerkb/build/debug/poa /scripts/clerkb/ +COPY build/clerkb/build/debug/state /scripts/clerkb/ + +# /scripts/godwoken-scripts +COPY build/godwoken-scripts/build/release/* /scripts/godwoken-scripts/ +COPY build/godwoken-scripts/c/build/*-generator /scripts/godwoken-scripts/ +COPY build/godwoken-scripts/c/build/*-validator /scripts/godwoken-scripts/ +COPY build/godwoken-scripts/c/build/account_locks/* /scripts/godwoken-scripts/ + +# /scripts/godwoken-polyjuice +COPY build/godwoken-polyjuice/build/*generator* /scripts/godwoken-polyjuice/ +COPY build/godwoken-polyjuice/build/*validator* /scripts/godwoken-polyjuice/ + +# godwoken +COPY build/godwoken/target/release/godwoken /bin/godwoken +COPY build/godwoken/target/release/gw-tools /bin/gw-tools + +CMD [ "godwoken", "--version" ] diff --git a/Makefile b/Makefile index 60b606f..73dd277 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ CLERKB_REPO := https://github.com/nervosnetwork/clerkb.git # components tags GODWOKEN_REF := v0.10.4 GODWOKEN_SCRIPTS_REF := v0.8.4 -POLYJUICE_REF := refs/pull/142/head +POLYJUICE_REF := v0.8.11 CLERKB_REF := v0.4.0 define prepare_repo @@ -32,6 +32,7 @@ prepare-repos: $(call prepare_repo,$(POLYJUICE_REPO),$(POLYJUICE_REF),godwoken-polyjuice) echo "::set-output name=POLYJUICE_REF::$(POLYJUICE_REF) $$(cd build/godwoken-polyjuice && git rev-parse --short HEAD)" >> versions $(call prepare_repo,$(CLERKB_REPO),$(CLERKB_REF),clerkb) + echo "::set-output name=CLERKB_REF::$(CLERKB_REF) $$(cd build/clerkb && git rev-parse --short HEAD)" >> versions build-components: prepare-repos cd build/godwoken-polyjuice && make dist && cd - @@ -74,4 +75,3 @@ test-scripts-files: test-polyjuice-files: source tool.sh && check_polyjuice_files_exists - diff --git a/README.md b/README.md index acb6d19..44b2164 100644 --- a/README.md +++ b/README.md @@ -77,5 +77,3 @@ $ docker run --rm godwoken-prebuilds find /scripts /scripts/clerkb/state /scripts/clerkb/poa ``` - -Finally, the original [Web3 compatible RPC layer](https://github.com/nervosnetwork/godwoken-web3) is move to [this js-prebuild image](https://github.com/RetricSu/godwoken-docker-js-prebuilds). diff --git a/tool.sh b/tool.sh index ee494b8..8c58c17 100644 --- a/tool.sh +++ b/tool.sh @@ -21,7 +21,7 @@ check_polyjuice_files_exists(){ local -a arr=( "generator" "generator_log" "validator" "validator_log" "generator.debug" "generator_log.debug" "validator.debug" "validator_log.debug" - ) + ) local path=`pwd`/test-result/scripts/godwoken-polyjuice check_multiple_files_exists "$path" "${arr[@]}" }