-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Multistage cargo build for x86 and ARM
- Conditionally `cargo build` for platforms of x86_64 or ARM. - In the final Docker stage we copy the built binary to alpine, and run with environment: - $LND_HOST, $LND_GRPC_PORT, $TLS_FILE, $MACAROON_FILE" Don't copy everything! Copy static later fix onion endpoint to http
- Loading branch information
1 parent
943cb87
commit 00b766d
Showing
5 changed files
with
181 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Test | ||
|
||
on: | ||
push: | ||
branches: [ "master" ] | ||
pull_request: | ||
branches: [ "master" ] | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: KengoTODA/actions-setup-docker-compose@main | ||
with: | ||
version: '2.10.2' | ||
- uses: actions/checkout@v3 | ||
- name: Build | ||
run: cargo build --verbose | ||
- name: Run tests | ||
run: cargo test --verbose -- --nocapture |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Multistage Build for Loin | ||
# | ||
# x86_64-unknown-linux-musl | ||
# aarch64-unknown-linux-musl | ||
# | ||
# Conditionally `cargo build` for platforms of x86_64 or ARM. | ||
# Use musl for static linking, producing a standalone executable with no dependencies. | ||
# In the final Docker stage we copy the built binary to alpine, and run with environment: | ||
# $LND_HOST, $LND_GRPC_PORT, $TLS_FILE, $MACAROON_FILE" | ||
|
||
## Initial build Stage | ||
FROM rustlang/rust:nightly AS builder | ||
# Target architecture argument used to change build | ||
ARG TARGETARCH | ||
# Some nicer rust debugging | ||
ENV RUSTFLAGS="-Z macro-backtrace" | ||
ENV RUST_BACKTRACE=1 | ||
# Copy the required build files. In this case, these are all the files that | ||
# are used for both architectures. | ||
WORKDIR /usr/src/loin/ | ||
COPY Cargo.toml Cargo.lock build.rs config_spec.toml ./ | ||
COPY src/ ./src/ | ||
# COPY static/ /usr/share/loin/static/ | ||
|
||
## x86_64 | ||
FROM builder AS branch-version-amd64 | ||
RUN echo "Preparing to cargo build for x86_64 (${TARGETARCH})" | ||
# Install the required dependencies to build for `musl` static linking | ||
RUN apt-get update && apt-get install -y musl-tools musl-dev | ||
# Add our x86 target to rust, then compile and install | ||
RUN rustup target add x86_64-unknown-linux-musl | ||
RUN cargo install --target x86_64-unknown-linux-musl --path . | ||
|
||
# ARM | ||
FROM builder AS branch-version-arm64 | ||
RUN echo "Preparing to cargo build for arm (${TARGETARCH})" | ||
# Install the required dependencies to build for `musl` static linking for arm. | ||
RUN apt-get update && apt-get install musl-tools clang llvm -y | ||
# Add our arm target to rust, some build variables, then compile and install | ||
RUN rustup target add aarch64-unknown-linux-musl | ||
ENV CC_aarch64_unknown_linux_musl=clang | ||
ENV AR_aarch64_unknown_linux_musl=llvm-ar | ||
ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_RUSTFLAGS="-Clink-self-contained=yes -Clinker=rust-lld" | ||
RUN cargo install --target aarch64-unknown-linux-musl --path . | ||
|
||
# We build for either x86_64 or ARM from above options using the docker $TARGETARCH | ||
FROM branch-version-${TARGETARCH} AS chosen_builder | ||
RUN echo "Called build!" | ||
|
||
# Run Loin from a final debian container | ||
FROM debian:buster-slim | ||
# COPY --chown=1000:1000 . . | ||
USER 1000 | ||
|
||
# Copy just the binary from our build stage | ||
COPY --from=chosen_builder /usr/local/cargo/bin/loin /usr/local/bin/loin | ||
COPY run_loin /usr/local/bin/run_loin | ||
COPY static/ /usr/share/loin/static/ | ||
|
||
# Expose any necessary ports | ||
EXPOSE 4444 | ||
# Run | ||
CMD ["run_loin"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/sh | ||
|
||
# Old: create loin config (we may want some persistent & modifyable config in the future, will need a volume) | ||
# CONF=loin.conf | ||
# if [ ! -f $CONF ] | ||
# then | ||
# touch $CONF | ||
# echo "bind_port=4444" >> $CONF | ||
# echo "lnd_address=\"https://lightning_lnd_1:$LND_GRPC_PORT\"" >> $CONF | ||
# echo "lnd_cert_path=\"$TLS_FILE\"" >> $CONF | ||
# echo "lnd_macaroon_path=\"$MACAROON_FILE\"" >> $CONF | ||
# echo "endpoint=\"https://$APP_HIDDEN_SERVICE\"" >> $CONF | ||
# fi | ||
# cat $CONF | ||
#loin --conf $CONF | ||
|
||
echo "Running loin" | ||
loin --bind-port=4444 --lnd-address=https://lightning_lnd_1:$LND_GRPC_PORT --lnd-cert-path=$TLS_FILE --lnd-macaroon-path=$MACAROON_FILE --endpoint=http://$APP_HIDDEN_SERVICE | ||
echo "STOPPED RUNNING LOIN" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters