Skip to content

Commit

Permalink
Merge pull request #58 from dappnode/dappnodedev/improve-build
Browse files Browse the repository at this point in the history
Improve package build
  • Loading branch information
pablomendezroyo authored Nov 22, 2023
2 parents 6367112 + 0e48df4 commit 5cafdf5
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 34 deletions.
20 changes: 11 additions & 9 deletions flyway/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
ARG UPSTREAM_VERSION

##############
# MIGRATIONS #
##############
FROM debian:bullseye-slim as postgres-migrations
FROM alpine:3.15.10 as postgres-migrations
ARG UPSTREAM_VERSION
WORKDIR /usr/src/app
RUN apt update && apt install -y wget
# Get migrations from consensys web3signer repo
# path is /usr/src/app/web3signer-21.10.0/slashing-protection/src/main/resources/migrations/postgresql

# Install wget and other dependencies, if necessary
RUN apk --no-cache add wget

# Get migrations from ConsenSys web3signer repository
RUN wget -q https://github.com/ConsenSys/web3signer/archive/refs/tags/${UPSTREAM_VERSION}.tar.gz && \
tar -xvf ${UPSTREAM_VERSION}.tar.gz
tar -xvf ${UPSTREAM_VERSION}.tar.gz && \
rm ${UPSTREAM_VERSION}.tar.gz

##########
# FLYWAY #
##########
FROM flyway/flyway:9.16.1-alpine
ARG UPSTREAM_VERSION
RUN apk update && apk add postgresql-client

RUN apk update && apk --no-cache add postgresql-client
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh && rm /flyway/sql/put-your-sql-migrations-here.txt
RUN chmod +x /usr/local/bin/entrypoint.sh && rm -rf /flyway/sql/*
COPY --from=postgres-migrations /usr/src/app/web3signer-${UPSTREAM_VERSION}/slashing-protection/src/main/resources/migrations/postgresql/* /flyway/sql/
ENTRYPOINT ["entrypoint.sh"]
2 changes: 1 addition & 1 deletion getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

- This is the entrypoint for handling your validator keystores
- Web3signer takes care for signing requests of your validator
- Web3signer supports client diversity, working with different clients such as [Prysm](http://my.dappnode/#/installer/prysm.dnp.dappnode.eth), [Lighthouse](http://my.dappnode/#/installer/lighthouse.dnp.dappnode.eth), [Teku](http://my.dappnode/#/installer/teku.dnp.dappnode.eth) and [Nimbus](http://my.dappnode/#/installer/nimbus.dnp.dappnode.eth)
- Web3signer supports client diversity, working with different clients such as [Prysm](http://my.dappnode/installer/dnp/prysm.dnp.dappnode.eth), [Lighthouse](http://my.dappnode/installer/dnp/lighthouse.dnp.dappnode.eth), [Teku](http://my.dappnode/installer/dnp/teku.dnp.dappnode.eth) and [Nimbus](http://my.dappnode/installer/dnp/nimbus.dnp.dappnode.eth)
- The Flyway service takes care of importing the previous version's slashing protection database when an update is installed, so it's meant to run only once per update, and it is normal to see that the Flyway service is stopped
45 changes: 22 additions & 23 deletions postgres/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
ARG UPSTREAM_VERSION

##########
# FLYWAY #
##########
#FROM flyway/flyway:8.0.5-alpine as binary-flyway
#COPY --from=binary-flyway /flyway/flyway /usr/local/bin/flyway

##############
# MIGRATIONS #
##############
FROM debian:bullseye-slim as postgres-migrations
FROM alpine:3.15.10 as postgres-migrations
ARG UPSTREAM_VERSION
WORKDIR /usr/src/app

RUN apt update && apt install -y wget
# Get migrations from consensys web3signer repo
# path is /usr/src/app/web3signer-21.10.0/slashing-protection/src/main/resources/migrations/postgresql
# Install wget and other dependencies, if necessary
RUN apk --no-cache add wget

# Get migrations from ConsenSys web3signer repository
RUN wget -q https://github.com/ConsenSys/web3signer/archive/refs/tags/${UPSTREAM_VERSION}.tar.gz && \
tar -xvf ${UPSTREAM_VERSION}.tar.gz
tar -xvf ${UPSTREAM_VERSION}.tar.gz && \
rm ${UPSTREAM_VERSION}.tar.gz

############
# POSTGRES #
############
FROM postgres:14.1-bullseye
FROM postgres:14.1-alpine3.15

ARG UPSTREAM_VERSION
ENV POSTGRES_PASSWORD=mainnet
ENV PGPASSWORD=mainnet
ENV POSTGRES_USER=postgres
ENV POSTGRES_DB=web3signer-mainnet

RUN apt update && apt install -y rename
ENV POSTGRES_PASSWORD=mainnet \
PGPASSWORD=mainnet \
POSTGRES_USER=postgres \
POSTGRES_DB=web3signer-mainnet \
INITDB_DIR=/docker-entrypoint-initdb.d/

COPY rename_files.sh /usr/local/bin/rename_files.sh

COPY --from=postgres-migrations /usr/src/app/web3signer-${UPSTREAM_VERSION}/slashing-protection/src/main/resources/migrations/postgresql/* ${INITDB_DIR}

RUN /usr/local/bin/rename_files.sh

COPY --from=postgres-migrations /usr/src/app/web3signer-${UPSTREAM_VERSION}/slashing-protection/src/main/resources/migrations/postgresql/* /docker-entrypoint-initdb.d/
# Rename scripts to be executed in alfabetical order
RUN rename 's/(\d+)(?=.*\.)/sprintf("%03d",$1)/eg' /docker-entrypoint-initdb.d/*
USER postgres

CMD ["postgres"]
CMD ["postgres"]
15 changes: 15 additions & 0 deletions postgres/rename_files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh

# Loop over each file in the /docker-entrypoint-initdb.d directory
for file in ${INITDB_DIR}*; do
# Extract the base name and directory of the file
dir=$(dirname "$file")
base=$(basename "$file")

# Use sed to modify the file name
# This will pad the first number in the file name with zeros to make it three digits long
new_base=$(echo "$base" | sed -r 's/([0-9]+)/000\1/g; s/0*([0-9]{3})/\1/g')

# Move (rename) the file to its new name
mv "$dir/$base" "$dir/$new_base"
done
2 changes: 1 addition & 1 deletion web3signer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ARG UPSTREAM_VERSION

FROM consensys/web3signer:$UPSTREAM_VERSION
USER root
RUN apt update && apt install ca-certificates unzip --yes
RUN apt update && apt install ca-certificates --yes

COPY /security /security
COPY entrypoint.sh /usr/bin/entrypoint.sh
Expand Down

0 comments on commit 5cafdf5

Please sign in to comment.