From 20713d92275a1099baaed9ce0c038785c94d6325 Mon Sep 17 00:00:00 2001 From: Lymarenko Lev Date: Wed, 8 Nov 2023 13:19:49 +0300 Subject: [PATCH 1/4] Add dockerfile --- .github/workflows/bens.yml | 106 +++++++++++++++++------------------ blockscout-ens/.dockerignore | 3 + blockscout-ens/.gitignore | 3 + blockscout-ens/Dockerfile | 31 ++++++++++ 4 files changed, 90 insertions(+), 53 deletions(-) create mode 100644 blockscout-ens/.dockerignore create mode 100644 blockscout-ens/.gitignore create mode 100644 blockscout-ens/Dockerfile diff --git a/.github/workflows/bens.yml b/.github/workflows/bens.yml index 4bb2ca37b..07e412aa4 100644 --- a/.github/workflows/bens.yml +++ b/.github/workflows/bens.yml @@ -104,56 +104,56 @@ jobs: - name: cargo clippy run: cargo clippy --all --all-targets --all-features -- -D warnings - # push: - # name: Docker build and docker push - # needs: - # - test - # - lint - # if: | - # always() && - # (needs.test.result == 'success' || needs.test.result == 'cancelled') && - # (needs.lint.result == 'success' || needs.lint.result == 'cancelled') - # timeout-minutes: 30 - # runs-on: ubuntu-latest - # steps: - # - name: Checkout repository - # uses: actions/checkout@v2 - - # - uses: actions-ecosystem/action-regex-match@v2 - # id: regex - # with: - # text: ${{ github.ref }} - # regex: '^(refs\/tags\/eth-bytecode-db\/(v\d+\.\d+\.\d+))|(refs\/heads\/(main))$' - - # - name: Extract tag name - # id: tags_extractor - # run: | - # t=${{ steps.regex.outputs.group2 }} - # m=${{ steps.regex.outputs.group4 }} - # (if ! [[ "$t" == "" ]]; then echo tags=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$t, ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest; elif ! [[ "$m" == "" ]]; then echo tags=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$m; else echo tags=; fi) >> $GITHUB_OUTPUT - - # - name: Login to GitHub Container Registry - # uses: docker/login-action@v1 - # with: - # registry: ${{ env.REGISTRY }} - # username: ${{ github.actor }} - # password: ${{ secrets.GITHUB_TOKEN }} - - # - name: Extract metadata for Docker - # id: meta - # uses: docker/metadata-action@v3 - # with: - # images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - - # - name: Set up Docker Buildx - # uses: docker/setup-buildx-action@v1 - # - name: Build and push - # uses: docker/build-push-action@v2 - # with: - # context: "eth-bytecode-db" - # file: "eth-bytecode-db/eth-bytecode-db-server/Dockerfile" - # push: ${{ steps.tags_extractor.outputs.tags != '' }} - # tags: ${{ steps.tags_extractor.outputs.tags }} - # labels: ${{ steps.meta.outputs.labels }} - # cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:build-cache - # cache-to: ${{ github.ref == 'refs/heads/main' && format('type=registry,ref={0}/{1}:build-cache,mode=max', env.REGISTRY, env.IMAGE_NAME) || '' }} + push: + name: Docker build and docker push + needs: + - test + - lint + if: | + always() && + (needs.test.result == 'success' || needs.test.result == 'cancelled') && + (needs.lint.result == 'success' || needs.lint.result == 'cancelled') + timeout-minutes: 60 + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - uses: actions-ecosystem/action-regex-match@v2 + id: regex + with: + text: ${{ github.ref }} + regex: '^(refs\/tags\/bens\/(v\d+\.\d+\.\d+))|(refs\/heads\/(main))$' + + - name: Extract tag name + id: tags_extractor + run: | + t=${{ steps.regex.outputs.group2 }} + m=${{ steps.regex.outputs.group4 }} + (if ! [[ "$t" == "" ]]; then echo tags=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$t, ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest; elif ! [[ "$m" == "" ]]; then echo tags=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$m; else echo tags=; fi) >> $GITHUB_OUTPUT + + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata for Docker + id: meta + uses: docker/metadata-action@v3 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Build and push + uses: docker/build-push-action@v2 + with: + context: "blockscout-ens" + file: "blockscout-ens/bens-server/Dockerfile" + push: ${{ steps.tags_extractor.outputs.tags != '' }} + tags: ${{ steps.tags_extractor.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:build-cache + cache-to: ${{ github.ref == 'refs/heads/main' && format('type=registry,ref={0}/{1}:build-cache,mode=max', env.REGISTRY, env.IMAGE_NAME) || '' }} diff --git a/blockscout-ens/.dockerignore b/blockscout-ens/.dockerignore new file mode 100644 index 000000000..68dd1a642 --- /dev/null +++ b/blockscout-ens/.dockerignore @@ -0,0 +1,3 @@ +.vscode +graph-node +target diff --git a/blockscout-ens/.gitignore b/blockscout-ens/.gitignore new file mode 100644 index 000000000..efb5659aa --- /dev/null +++ b/blockscout-ens/.gitignore @@ -0,0 +1,3 @@ +.env +bens-server/benchmark +graph-node \ No newline at end of file diff --git a/blockscout-ens/Dockerfile b/blockscout-ens/Dockerfile new file mode 100644 index 000000000..db118c783 --- /dev/null +++ b/blockscout-ens/Dockerfile @@ -0,0 +1,31 @@ +FROM lukemathwalker/cargo-chef:0.1.62-rust-1.72-buster as chef +WORKDIR /app +RUN rustup target add x86_64-unknown-linux-musl +RUN apt-get update && apt-get install -y curl wget unzip musl-dev musl-tools +RUN wget https://github.com/protocolbuffers/protobuf/releases/download/v21.12/protoc-21.12-linux-x86_64.zip -O ./protoc.zip \ + && unzip protoc.zip \ + && mv ./include/* /usr/include/ \ + && mv ./bin/protoc /usr/bin/protoc + +RUN wget https://github.com/grpc-ecosystem/grpc-gateway/releases/download/v2.15.0/protoc-gen-openapiv2-v2.15.0-linux-x86_64 -O ./protoc-gen-openapiv2 \ + && chmod +x protoc-gen-openapiv2 \ + && mv ./protoc-gen-openapiv2 /usr/bin/protoc-gen-openapiv2 + +FROM chef AS plan +COPY . . +RUN cargo chef prepare --recipe-path recipe.json + +FROM chef as cache +COPY --from=plan /app/recipe.json recipe.json +RUN cargo chef cook --release --recipe-path recipe.json + +FROM chef AS build +COPY . . +COPY --from=cache /app/target target +COPY --from=cache $CARGO_HOME $CARGO_HOME +RUN cargo build --release --bin app + +FROM debian:bookworm-slim AS runtime +WORKDIR /app +COPY --from=build /app/target/release/app /usr/local/bin +ENTRYPOINT ["/usr/local/bin/app"] From bf6b4abfab77cf7cb360d2e21589344289f7f12b Mon Sep 17 00:00:00 2001 From: Lymarenko Lev Date: Wed, 8 Nov 2023 13:27:24 +0300 Subject: [PATCH 2/4] Fix cicd --- .github/workflows/bens.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/bens.yml b/.github/workflows/bens.yml index 07e412aa4..1558e187b 100644 --- a/.github/workflows/bens.yml +++ b/.github/workflows/bens.yml @@ -151,7 +151,7 @@ jobs: uses: docker/build-push-action@v2 with: context: "blockscout-ens" - file: "blockscout-ens/bens-server/Dockerfile" + file: "blockscout-ens/Dockerfile" push: ${{ steps.tags_extractor.outputs.tags != '' }} tags: ${{ steps.tags_extractor.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} From 06d7a01aa1ff8409a23a017273d1772c2f1e97bb Mon Sep 17 00:00:00 2001 From: Lymarenko Lev Date: Wed, 8 Nov 2023 13:47:46 +0300 Subject: [PATCH 3/4] Fix dockerfile error --- blockscout-ens/Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/blockscout-ens/Dockerfile b/blockscout-ens/Dockerfile index db118c783..edbc190b4 100644 --- a/blockscout-ens/Dockerfile +++ b/blockscout-ens/Dockerfile @@ -23,9 +23,9 @@ FROM chef AS build COPY . . COPY --from=cache /app/target target COPY --from=cache $CARGO_HOME $CARGO_HOME -RUN cargo build --release --bin app +RUN cargo build --release --bin bens-server FROM debian:bookworm-slim AS runtime WORKDIR /app -COPY --from=build /app/target/release/app /usr/local/bin -ENTRYPOINT ["/usr/local/bin/app"] +COPY --from=build /app/target/release/bens-server /usr/local/bin +ENTRYPOINT ["/usr/local/bin/bens-server"] From 5acea12948d3d1acca18e4fe832b017748dca6f9 Mon Sep 17 00:00:00 2001 From: Lymarenko Lev Date: Wed, 8 Nov 2023 15:21:07 +0300 Subject: [PATCH 4/4] remove .gitignore --- blockscout-ens/.gitignore | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 blockscout-ens/.gitignore diff --git a/blockscout-ens/.gitignore b/blockscout-ens/.gitignore deleted file mode 100644 index efb5659aa..000000000 --- a/blockscout-ens/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -.env -bens-server/benchmark -graph-node \ No newline at end of file