Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update docker image for better caching #115

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 27 additions & 28 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Built by Akito
# npub1wprtv89px7z2ut04vvquscpmyfuzvcxttwy2csvla5lvwyj807qqz5aqle

FROM alpine:3.18.3 AS build

ENV TZ=Europe/London
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this necessarry, isn't UTC the default?


WORKDIR /build

COPY . .
# Runtime dependencies
FROM alpine:3.18.3 AS runtime-deps
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can update to 3.20.2 in another PR

RUN apk --no-cache update && apk --no-cache add \
lmdb \
flatbuffers \
libsecp256k1 \
libb2 \
zstd \
libressl

RUN \
apk --no-cache add \
# Build dependencies
FROM runtime-deps AS build-deps
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid repeating the image and avoid redownloading the dependencies

RUN apk update && apk add \
linux-headers \
git \
g++ \
Expand All @@ -24,25 +24,24 @@ RUN \
lmdb-dev \
flatbuffers-dev \
libsecp256k1-dev \
zstd-dev \
&& rm -rf /var/cache/apk/* \
Copy link
Author

@l0rinc l0rinc Jul 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we already have --no-cache in the runtime build:

docker images

REPOSITORY              TAG       IMAGE ID       CREATED          SIZE
strfry_image_original   latest    bba6a16b8521   14 seconds ago   143MB

and

REPOSITORY     TAG       IMAGE ID       CREATED         SIZE
strfry_image   latest    22a7b0451b35   7 minutes ago   143MB

btw, the Ubuntu one is a lot bigger:

REPOSITORY            TAG       IMAGE ID       CREATED         SIZE
strfry_image_ubuntu   latest    312188f2bc47   3 minutes ago   206MB

&& git submodule update --init \
&& make setup-golpe \
&& make -j4
zstd-dev

FROM alpine:3.18.3
# Stage 1: Build the application using the build-deps base image
FROM build-deps AS build

WORKDIR /app
WORKDIR /build

RUN \
apk --no-cache add \
lmdb \
flatbuffers \
libsecp256k1 \
libb2 \
zstd \
libressl \
&& rm -rf /var/cache/apk/*
COPY . .

RUN make clean \
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clean was added to the runtime to avoid reusing the local build artefacts

&& git submodule update --init \
&& make setup-golpe \
&& make -j4

# Stage 2: Create the final runtime image using the runtime-deps base image
FROM runtime-deps AS runtime

WORKDIR /app

COPY --from=build /build/strfry strfry

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ A C++20 compiler is required, along with a few other common dependencies. On Deb
git clone https://github.com/hoytech/strfry && cd strfry/
git submodule update --init
make setup-golpe
make -j4
make -j$(nproc)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should be able to use all processors when not in a docker image


#### FreeBSD

pkg install -y gcc gmake cmake git perl5 openssl lmdb flatbuffers libuv libinotify zstr secp256k1 zlib-ng
git clone https://github.com/hoytech/strfry && cd strfry/
git submodule update --init
gmake setup-golpe
gmake -j4
gmake -j$(sysctl -n hw.ncpu)


### Running a relay
Expand Down
4 changes: 2 additions & 2 deletions ubuntu.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:jammy as build
FROM ubuntu:jammy AS build
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to silence the warning

ENV TZ=Europe/London
WORKDIR /build
RUN apt update && apt install -y --no-install-recommends \
Expand All @@ -12,7 +12,7 @@ RUN make setup-golpe
RUN make clean
RUN make -j4

FROM ubuntu:jammy as runner
FROM ubuntu:jammy AS runner
WORKDIR /app

RUN apt update && apt install -y --no-install-recommends \
Expand Down