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

build: tidy dockerfile #1477

Merged
merged 1 commit into from
May 27, 2023
Merged
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
59 changes: 54 additions & 5 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,54 @@
**/.git
**/.gitignore
**/.github
**/tests
Dockerfile
/.git
/.gitignore
/.github
/tests
/Dockerfile

# Prerequisites
*.d

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app

*.pyc
*.swp
*.swo
.DS_Store
version.h

.idea
.vscode
.cache

compactdb
testdb

build
Copy link
Member Author

Choose a reason for hiding this comment

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

Add .gitignore content. Avoid build content conflict issues.

cmake-build-*
31 changes: 7 additions & 24 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ FROM alpine:3.16 as build

ARG MORE_BUILD_ARGS

# workaround tzdata install hanging
ENV TZ=Etc/UTC
Copy link
Member Author

Choose a reason for hiding this comment

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

After switching to Alpine, we don't need this trick.

RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

RUN apk update && apk add git gcc g++ make cmake ninja autoconf automake libtool python3 linux-headers curl openssl-dev libexecinfo-dev redis
WORKDIR /kvrocks

Expand All @@ -31,36 +27,23 @@ RUN ./x.py build -DENABLE_OPENSSL=ON -DPORTABLE=ON -DCMAKE_BUILD_TYPE=Release -j

FROM alpine:3.16

ENV TZ=Etc/UTC
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

RUN apk upgrade && apk add libexecinfo

WORKDIR /kvrocks

RUN mkdir /var/run/kvrocks && mkdir /var/lib/kvrocks

RUN addgroup -S kvrocks && adduser -D -H -S -G kvrocks kvrocks

RUN chown kvrocks:kvrocks /var/run/kvrocks && chown kvrocks:kvrocks /var/lib/kvrocks

USER kvrocks

COPY --from=build /kvrocks/build/kvrocks ./bin/
COPY --from=build /usr/bin/redis-cli ./bin/

HEALTHCHECK --interval=10s --timeout=1s --start-period=30s --retries=3 CMD ./bin/redis-cli -p 6666 PING | grep -E '(PONG|NOAUTH)' || exit 1

ENV PATH="$PATH:/kvrocks/bin"

VOLUME /var/lib/kvrocks

RUN chown kvrocks:kvrocks /var/lib/kvrocks
Copy link
Member Author

Choose a reason for hiding this comment

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

Duplicated above.

COPY --from=build /kvrocks/build/kvrocks /bin/
Copy link
Member Author

Choose a reason for hiding this comment

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

Simplify a bit layout:

/bin/kvrocks
/bin/redis-cli
/kvrocks/<LICENSE/NOTICE>
/var/...

COPY --from=build /usr/bin/redis-cli /bin/

HEALTHCHECK --interval=10s --timeout=1s --start-period=30s --retries=3 \
CMD ./bin/redis-cli -p 6666 PING | grep -E '(PONG|NOAUTH)' || exit 1

COPY ./LICENSE ./NOTICE ./DISCLAIMER ./
COPY ./licenses ./licenses
COPY ./LICENSE ./NOTICE ./DISCLAIMER ./licenses /kvrocks/
COPY ./kvrocks.conf /var/lib/kvrocks/

EXPOSE 6666:6666

ENTRYPOINT ["./bin/kvrocks", "-c", "/var/lib/kvrocks/kvrocks.conf", "--dir", "/var/lib/kvrocks", "--pidfile", "/var/run/kvrocks/kvrocks.pid"]
ENTRYPOINT ["kvrocks", "-c", "/var/lib/kvrocks/kvrocks.conf", "--dir", "/var/lib/kvrocks", "--pidfile", "/var/run/kvrocks/kvrocks.pid"]