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

QB-1793 Update Dockerfile #253

Merged
merged 2 commits into from
May 1, 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
55 changes: 36 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,41 +1,58 @@
# Simple usage with a mounted data directory:
# > docker build -t stratos-chain .
# > docker run -it -p 46657:46657 -p 46656:46656 -v ~/.stratos-chain:/stratos-chain/.stratos-chain stratos-chain stratos-chain init
# > docker run -it -p 46657:46657 -p 46656:46656 -v ~/.stratos-chain:/stratos-chain/.stratos-chain stratos-chain stratos-chain start
FROM golang:1.15-alpine AS build-env
FROM golang:1.18-alpine AS build-env

# Set up dependencies
ENV PACKAGES curl make git libc-dev bash gcc linux-headers eudev-dev python3
ENV PACKAGES curl make git libc-dev bash gcc linux-headers eudev-dev python3 \
gmp-dev flex bison

# Install minimum necessary dependencies
RUN apk add --no-cache $PACKAGES
# Install pdc
RUN wget https://crypto.stanford.edu/pbc/files/pbc-0.5.14.tar.gz \
&& tar -xf pbc-0.5.14.tar.gz \
&& cd pbc-0.5.14/ \
&& ./configure \
&& make \
&& make install \
&& ldconfig / \
&& cd .. && rm -rf pbc-0.5.14/ pbc-0.5.14.tar.gz

# Set working directory for the build
WORKDIR /go/src/github.com/stratosnet/stratos-chain

# Add source files
COPY . .
RUN make install

RUN go version

# Install minimum necessary dependencies, build Cosmos SDK, remove packages
RUN apk add --no-cache $PACKAGES && \
make install

# Final image
FROM alpine:edge

ENV STRATOS /stchaind
ENV WORK_DIR /stchaind
ENV RUN_AS_USER stratos

# Install ca-certificates
RUN apk add --update ca-certificates
RUN apk add --update ca-certificates gmp-dev

RUN addgroup stratos && \
adduser -S -G stratos stratos -h "$STRATOS"
ARG chain_id
ARG moniker
ARG uid=2048
ARG gid=2048

USER stratos
RUN addgroup --gid $gid "$RUN_AS_USER" && \
adduser -S -G "$RUN_AS_USER" --uid $uid "$RUN_AS_USER" -h "$WORK_DIR"

WORKDIR $STRATOS
ENV CHAIN_ID=${chain_id:-DEFAULT}
ENV MONIKER=${moniker:-stratos-node}
WORKDIR $WORK_DIR

# Copy over binaries from the build-env
COPY --from=build-env /go/bin/stchaind /usr/bin/stchaind
COPY --from=build-env /usr/local/lib/libpbc.so.1.0.0 /usr/local/lib/libpbc.so.1.0.0

RUN cd /usr/local/lib && { ln -s -f libpbc.so.1.0.0 libpbc.so.1 || { rm -f libpbc.so.1 && ln -s libpbc.so.1.0.0 libpbc.so.1; }; } \
&& cd /usr/local/lib && { ln -s -f libpbc.so.1.0.0 libpbc.so || { rm -f libpbc.so && ln -s libpbc.so.1.0.0 libpbc.so; }; }

# Run stchaind by default, omit entrypoint to ease using container with stchaincli
CMD ["stchaind"]
COPY entrypoint.sh /usr/bin/entrypoint.sh
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["/usr/bin/entrypoint.sh"]
CMD ["stchaind start"]
13 changes: 10 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#!/usr/bin/make -f

BUILDDIR ?= $(CURDIR)/build

APP_VER := v0.9.1
COMMIT := $(GIT_COMMIT_HASH)
TEST_DOCKER_REPO=stratos-chain-e2e
COMMIT := $(shell git log -1 --format='%H')
TEST_DOCKER_REPO=stratos-chain

ifeq ($(COMMIT),)
VERSION := $(APP_VER)
VERSION := $(APP_VER)
else
VERSION := $(APP_VER)-$(COMMIT)
endif
Expand Down Expand Up @@ -66,4 +68,9 @@ build-docker-e2e:
@docker tag ${TEST_DOCKER_REPO}:$(shell git rev-parse --short HEAD) ${TEST_DOCKER_REPO}:$(shell git rev-parse --abbrev-ref HEAD | sed 's#/#_#g')
@docker tag ${TEST_DOCKER_REPO}:$(shell git rev-parse --short HEAD) ${TEST_DOCKER_REPO}:latest

build-docker:
@docker build -f Dockerfile -t ${TEST_DOCKER_REPO}:$(shell git rev-parse --short HEAD) --build-arg uid=$(shell id -u) --build-arg gid=$(shell id -g) .
@docker tag ${TEST_DOCKER_REPO}:$(shell git rev-parse --short HEAD) ${TEST_DOCKER_REPO}:$(shell git rev-parse --abbrev-ref HEAD | sed 's#/#_#g')
@docker tag ${TEST_DOCKER_REPO}:$(shell git rev-parse --short HEAD) ${TEST_DOCKER_REPO}:latest

.PHONY: build-linux build-mac build clean
28 changes: 28 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/sh
chown -R $RUN_AS_USER $WORK_DIR

if [ ! -d "$WORK_DIR/.stchaind" ]
then
echo "[entrypoint] Init stratos node..."
su -s /bin/sh - $RUN_AS_USER -c "stchaind init stratos-node"

if [ "$CHAIN_ID" == "DEFAULT" ]
then
genesis_file_URL=https://raw.githubusercontent.com/stratosnet/stratos-chain-testnet/main/genesis.json
config_file_URL=https://raw.githubusercontent.com/stratosnet/stratos-chain-testnet/main/config.toml
else
genesis_file_URL=https://raw.githubusercontent.com/stratosnet/stratos-chain-testnet/main/$CHAIN_ID/genesis.json
config_file_URL=https://raw.githubusercontent.com/stratosnet/stratos-chain-testnet/main/$CHAIN_ID/config.toml
fi

echo "[entrypoint] Download genesis.json from $genesis_file_URL"
su -s /bin/sh - $RUN_AS_USER -c "wget $genesis_file_URL -O $WORK_DIR/.stchaind/config/genesis.json"

echo "[entrypoint] Download config.toml from $config_file_URL"
su -s /bin/sh - $RUN_AS_USER -c "wget $config_file_URL -O $WORK_DIR/.stchaind/config/config.toml"

echo "[entrypoint] Set the node moniker to '$MONIKER'"
su -s /bin/sh - $RUN_AS_USER -c "sed -i 's/moniker = \".*\"/moniker = \"'$MONIKER'\"/g' $WORK_DIR/.stchaind/config/config.toml"
fi

su -s /bin/sh - $RUN_AS_USER -c "$@"