Skip to content

Commit

Permalink
rebase and solve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
alexstratos committed May 17, 2023
1 parent c7d6f5d commit 13851d6
Show file tree
Hide file tree
Showing 23 changed files with 72 additions and 48 deletions.
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"]
9 changes: 8 additions & 1 deletion 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.10.0
COMMIT := $(GIT_COMMIT_HASH)
TEST_DOCKER_REPO=stratos-chain-e2e

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 "$@"
Empty file.

This file was deleted.

Empty file.

This file was deleted.

Binary file not shown.
Empty file.

This file was deleted.

Empty file.

This file was deleted.

Binary file not shown.
Binary file not shown.

This file was deleted.

Empty file.

This file was deleted.

Binary file not shown.
Empty file.

This file was deleted.

Empty file.

This file was deleted.

Binary file not shown.

0 comments on commit 13851d6

Please sign in to comment.