Skip to content

Commit

Permalink
dockerize the exporter (#3)
Browse files Browse the repository at this point in the history
making
1. dockerfile
2. action can build image into ghcr
3. fixing code coverage issue
4. adding dependency bot to check action
  • Loading branch information
tommady authored Jan 19, 2022
1 parent ea7c061 commit 4f6664e
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: daily
- package-ecosystem: cargo
directory: "/"
schedule:
Expand Down
21 changes: 16 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,33 @@ jobs:

- name: Run Tests
run: cargo test --all --all-features --no-fail-fast

coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

# TODO:
# there has an issue of rust 2022-01-15 nightly version toolchain
# https://github.com/taiki-e/cargo-llvm-cov/issues/128
# so do a work around here to tag older nightly version
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
- name: Install Rust nightly llvm-tools-preview component
run: rustup toolchain install nightly --component llvm-tools-preview
toolchain: nightly-2022-01-14
override: true
components: llvm-tools-preview

- name: Install cargo-llvm-cov
run: curl -LsSf https://github.com/taiki-e/cargo-llvm-cov/releases/latest/download/cargo-llvm-cov-x86_64-unknown-linux-gnu.tar.gz | tar xzf - -C ~/.cargo/bin
uses: taiki-e/install-action@v1
with:
tool: cargo-llvm-cov

- name: Generate code coverage
run: cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v2
with:
files: lcov.info
fail_ci_if_error: true
41 changes: 41 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,44 @@ jobs:
asset_path: ./findora-exporter_${{ steps.info.outputs.version }}_amd64.deb
asset_name: findora-exporter_${{ steps.info.outputs.version }}_amd64.deb
asset_content_type: application/x-deb

publish-image:
name: Publish image releases
needs: check
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2
with:
fetch-depth: 1

- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login Github Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract Metadata for Docker
id: meta
uses: docker/metadata-action@v3
with:
images: ghcr.io/FindoraNetwork/findora-exporter
tags: |
type=raw,value={{tag}}
type=raw,value=latest
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: .
push: true
platforms: linux/amd64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "findora-exporter"
version = "1.1.0"
version = "1.1.1"
authors = ["tommady <[email protected]>"]
edition = "2021"
readme = "README.md"
Expand Down
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM docker.io/rust:slim AS builder

RUN apt-get update -y && apt-get install -y musl-tools
ARG TARGETPLATFORM
RUN case "$TARGETPLATFORM" in \
"linux/amd64") echo x86_64-unknown-linux-musl > /rust_targets ;; \
*) exit 1 ;; \
esac

RUN rustup target add $(cat /rust_targets)

COPY . ./exporter
WORKDIR /exporter
RUN cargo build --release --target $(cat /rust_targets)
RUN cp target/$(cat /rust_targets)/release/findora-exporter ./
RUN strip --strip-all ./findora-exporter

FROM docker.io/busybox:latest

COPY --from=builder /exporter/findora-exporter /exporter

EXPOSE 9090
ENTRYPOINT ["/exporter", "--config", "/config.json"]

0 comments on commit 4f6664e

Please sign in to comment.