github.com/rkt/rkt@v1.30.1-0.20200224141603-171c416fac02/Documentation/examples/build-container/postgres/build-postgres.sh (about)

     1  #!/usr/bin/env bash
     2  set -e
     3  
     4  if [ "$EUID" -ne 0 ]; then
     5      echo "This script uses functionality which requires root privileges"
     6      exit 1
     7  fi
     8  
     9  PGDATA=/var/lib/postgresql/data
    10  
    11  # Start the build with an empty ACI
    12  acbuild --debug begin
    13  
    14  # In the event of the script exiting, end the build
    15  trap "{ export EXT=$?; acbuild --debug end && exit $EXT; }" EXIT
    16  
    17  # Name the ACI
    18  acbuild --debug set-name example.com/postgres
    19  
    20  # Based on alpine
    21  acbuild --debug dep add quay.io/coreos/alpine-sh
    22  
    23  # Install postgres and bash
    24  acbuild --debug run -- apk update
    25  acbuild --debug run -- apk add postgresql bash
    26  
    27  # Create postgres data directory
    28  acbuild --debug run -- mkdir -p $PGDATA
    29  acbuild --debug run -- chown -R postgres:postgres $PGDATA
    30  
    31  # Create postgres run directory
    32  acbuild --debug run -- mkdir -p /var/run/postgresql
    33  acbuild --debug run -- chown -R postgres:postgres /var/run/postgresql
    34  
    35  # Add a mount point for postgres data
    36  acbuild --debug mount add data $PGDATA
    37  
    38  # Add a mount point for custom initialization data
    39  acbuild --debug mount add custom-sql /customize.sql
    40  
    41  # Set PGDATA env variable
    42  acbuild --debug environment add PGDATA $PGDATA
    43  
    44  # Set user and group
    45  acbuild --debug set-user postgres
    46  acbuild --debug set-group postgres
    47  
    48  # Set postgres user, group, and test-db
    49  acbuild --debug environment add POSTGRES_USER rkt
    50  acbuild --debug environment add POSTGRES_PASSWORD rkt
    51  acbuild --debug environment add POSTGRES_DB rkt
    52  
    53  # Add pre-start hook that will set up the database
    54  acbuild --debug copy postgres-prestart.sh /root/postgres-prestart.sh
    55  acbuild --debug set-event-handler pre-start /root/postgres-prestart.sh postgres
    56  
    57  # Add postgres port
    58  acbuild --debug port add postgres tcp 5432
    59  
    60  # Run postgres server
    61  acbuild --debug set-exec postgres
    62  
    63  # Write the result
    64  acbuild --debug write --overwrite postgres-latest-linux-amd64.aci