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

Improve package build #71

Merged
merged 5 commits into from
Nov 22, 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
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"]
46 changes: 23 additions & 23 deletions postgres/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
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
2 changes: 1 addition & 1 deletion web3signer/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading