Skip to content

Commit

Permalink
Merge pull request #670 from blockscout/lymarenkolev/bens/add-dockerfile
Browse files Browse the repository at this point in the history
Bens: add dockerfile
  • Loading branch information
sevenzing authored Nov 8, 2023
2 parents a7c664e + 5acea12 commit 70992ae
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 53 deletions.
106 changes: 53 additions & 53 deletions .github/workflows/bens.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/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) || '' }}
3 changes: 3 additions & 0 deletions blockscout-ens/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.vscode
graph-node
target
31 changes: 31 additions & 0 deletions blockscout-ens/Dockerfile
Original file line number Diff line number Diff line change
@@ -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 bens-server

FROM debian:bookworm-slim AS runtime
WORKDIR /app
COPY --from=build /app/target/release/bens-server /usr/local/bin
ENTRYPOINT ["/usr/local/bin/bens-server"]

0 comments on commit 70992ae

Please sign in to comment.