diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..7a17791 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +target/ +.git/ +.github/ +Dockerfile +Makefile diff --git a/.github/workflows/cont_integration.yml b/.github/workflows/cont_integration.yml index 21f9ad7..030b270 100644 --- a/.github/workflows/cont_integration.yml +++ b/.github/workflows/cont_integration.yml @@ -51,34 +51,14 @@ jobs: - name: Test run: cargo test - -# check-azure: -# name: Check Azure -# runs-on: ubuntu-20.04 -# steps: -# - name: Checkout -# uses: actions/checkout@v4 -# - name: Cache -# uses: actions/cache@v2 -# with: -# path: | -# ~/.cargo/registry -# ~/.cargo/git -# target -# key: ${{ runner.os }}-cargo-${{ github.job }}-${{ hashFiles('**/Cargo.toml','**/Cargo.lock') }} -# - run: sudo apt-get update || exit 1 -# - run: sudo apt-get install -y clang musl musl-tools || exit 1 -# - run: sudo ln -s /usr/bin/g++ /usr/bin/musl-g++ -# - name: Set default toolchain -# run: rustup default 1.63.0 -# - name: Set profile -# run: rustup set profile minimal -# - name: Add target musl -# run: rustup target add x86_64-unknown-linux-musl -# - name: Update toolchain -# run: rustup update -# - name: Check -# run: cargo build --release --target=x86_64-unknown-linux-musl + build-docker: + name: build docker + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Build the Docker image + run: docker build --file Dockerfile --tag bdk-reserves-web . fmt: name: Rust fmt diff --git a/Cargo.toml b/Cargo.toml index e327d87..319375a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,14 @@ bdk = "0.28" bdk-reserves = "0.28" env_logger = "0.10" log = "0.4" -base64 = "^0.13" +base64 = "0.13" [dev-dependencies] -actix-rt = "1" \ No newline at end of file +actix-rt = "1" + +[profile.release] +opt-level = 'z' # Optimize for size +lto = true # Enable link-time optimization +codegen-units = 1 # Reduce number of codegen units to increase optimizations +panic = 'abort' # Abort on panic +strip = true # Strip symbols from binary* diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..81fb2b6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM rust:1.72-alpine3.18 as builder +RUN apk add --no-cache build-base +USER bin +WORKDIR /app +COPY . . +RUN cargo test +RUN cargo build --release +RUN install -D target/release/bdk-reserves-web dist/bin/bdk-reserves-web +RUN ldd dist/bin/bdk-reserves-web | tr -s [:blank:] '\n' | grep ^/ | xargs -I % install -D % dist/% +RUN ln -s ld-musl-x86_64.so.1 dist/lib/libc.musl-x86_64.so.1 + +RUN rustup component add clippy-preview \ + && rustup component add rustfmt +RUN cargo install cargo-audit +RUN cargo fmt -- --check +RUN cargo clippy +#RUN cargo audit + +FROM scratch +COPY --from=builder /app/dist / +USER 65534 +ENTRYPOINT ["/bin/bdk-reserves-web"] \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b9be5e5 --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +TAG := bdk-reserves-web + +run: builder + docker run --rm --tty --env PORT=8888 --publish 8888:8888 ${TAG} + +builder: + docker build --tag ${TAG} .