diff --git a/flyway/Dockerfile b/flyway/Dockerfile index 89373f4..ea19d12 100644 --- a/flyway/Dockerfile +++ b/flyway/Dockerfile @@ -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"] \ No newline at end of file diff --git a/postgres/Dockerfile b/postgres/Dockerfile index fbe5683..f5e7012 100644 --- a/postgres/Dockerfile +++ b/postgres/Dockerfile @@ -1,37 +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=gnosis -ENV PGPASSWORD=gnosis -ENV POSTGRES_USER=postgres -ENV POSTGRES_DB=web3signer-gnosis -RUN apt update && apt install -y rename -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/* +ENV POSTGRES_PASSWORD=gnosis \ + PGPASSWORD=gnosis \ + POSTGRES_USER=postgres \ + POSTGRES_DB=web3signer-gnosis \ + 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 + +USER postgres -CMD ["postgres"] +CMD ["postgres"] \ No newline at end of file diff --git a/postgres/rename_files.sh b/postgres/rename_files.sh new file mode 100755 index 0000000..419eac1 --- /dev/null +++ b/postgres/rename_files.sh @@ -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 diff --git a/web3signer/Dockerfile b/web3signer/Dockerfile index a65067d..3bffaea 100644 --- a/web3signer/Dockerfile +++ b/web3signer/Dockerfile @@ -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 diff --git a/web3signer/entrypoint.sh b/web3signer/entrypoint.sh index d05aeaa..7f34c09 100755 --- a/web3signer/entrypoint.sh +++ b/web3signer/entrypoint.sh @@ -44,7 +44,7 @@ esac mkdir -p "$KEYFILES_DIR" mkdir -p "/opt/web3signer/manual_migration" -if grep -Fq "/opt/web3signer/keyfiles" ${KEYFILES_DIR}/*.yaml ;then +if grep -Fq "/opt/web3signer/keyfiles" ${KEYFILES_DIR}/*.yaml; then sed -i "s|/opt/web3signer/keyfiles|$KEYFILES_DIR|g" ${KEYFILES_DIR}/*.yaml fi