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

Misc fixes to allow local file to work with both Docker for Mac and C… #823

Merged
merged 5 commits into from
Mar 20, 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: 8 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,11 @@ jobs:
if: (matrix.project == 'rootNative') && startsWith(matrix.os, 'ubuntu')
run: /home/linuxbrew/.linuxbrew/bin/brew install s2n utf8proc

- name: Set up cert permissions
run: |
chmod 600 world/server.key
sudo chown 999 world/server.key

- name: Start up Postgres
run: docker-compose up -d
run: |
export SERVER_KEY=$(cat world/server.key)
export SERVER_CERT=$(cat world/server.crt)
docker-compose up -d

- name: Check that workflows are up to date
run: sbt githubWorkflowCheck
Expand Down Expand Up @@ -316,13 +314,11 @@ jobs:
~/Library/Caches/Coursier/v1
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Set up cert permissions
run: |
chmod 600 world/server.key
sudo chown 999 world/server.key

- name: Start up Postgres
run: docker-compose up -d
run: |
export SERVER_KEY=$(cat world/server.key)
export SERVER_CERT=$(cat world/server.crt)
docker-compose up -d

- run: sbt '++${{ matrix.scala }}' coverage rootJVM/test coverageReport

Expand Down
7 changes: 5 additions & 2 deletions bin/local
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ case $DIR in
;;
esac

# Fix postgres ssl key permissions.
chmod 600 world/server.key
# Export server files as environment variables
# so we can load them onto the file system
# as postgres user
export SERVER_KEY=$(cat world/server.key)
export SERVER_CERT=$(cat world/server.crt)

docker-compose $CMD $EXTRA_FLAGS
6 changes: 1 addition & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ ThisBuild / nativeBrewInstallCond := Some("matrix.project == 'rootNative'")

lazy val setupCertAndDocker = Seq(
WorkflowStep.Run(
commands = List("chmod 600 world/server.key", "sudo chown 999 world/server.key"),
name = Some("Set up cert permissions"),
),
WorkflowStep.Run(
commands = List("docker-compose up -d"),
commands = List("export SERVER_KEY=$(cat world/server.key)", "export SERVER_CERT=$(cat world/server.crt)", "docker-compose up -d"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of export, should these be set as proper env = Map(...) variables for the WorkflowStep ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sorry, I see, they are reading from a file 🤔

name = Some("Start up Postgres"),
)
)
Expand Down
7 changes: 4 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ services:
# main instance for testing
postgres:
image: postgres:11
command: -c ssl=on -c ssl_cert_file=/var/lib/postgresql/server.crt -c ssl_key_file=/var/lib/postgresql/server.key
volumes:
- ./world/fix_perms.sh:/docker-entrypoint-initdb.d/fix_perms.sh
- ./world/world.sql:/docker-entrypoint-initdb.d/world.sql
- ./world/ltree.sql:/docker-entrypoint-initdb.d/ltree.sql
- ./world/server.crt:/var/lib/postgresql/server.crt
- ./world/server.key:/var/lib/postgresql/server.key
- ./world/config.sql:/docker-entrypoint-initdb.d/config.sql
ports:
- 5432:5432
environment:
POSTGRES_USER: jimmy
POSTGRES_PASSWORD: banana
POSTGRES_DB: world
SERVER_KEY: $SERVER_KEY
SERVER_CERT: $SERVER_CERT
# for testing password-free login
trust:
image: postgres:11
Expand Down
3 changes: 3 additions & 0 deletions world/config.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER SYSTEM SET ssl_cert_file TO '/var/lib/postgresql/server.crt';
ALTER SYSTEM SET ssl_key_file TO '/var/lib/postgresql/server.key';
ALTER SYSTEM SET ssl TO 'ON';
16 changes: 16 additions & 0 deletions world/fix_perms.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

# Loads cert/key into container as environment variable so
# we can write it as postgres user in the container
#
# Bind mounting it from host on non-native Docker environments
# (e.g., OS X) leads to permission issues.

echo "$SERVER_CERT" > /var/lib/postgresql/server.crt
echo "$SERVER_KEY" > /var/lib/postgresql/server.key

cat /var/lib/postgresql/server.crt
cat /var/lib/postgresql/server.key

chmod 600 /var/lib/postgresql/server.key
chmod 600 /var/lib/postgresql/server.crt
2 changes: 1 addition & 1 deletion world/ltree.sql
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CREATE EXTENSION ltree ;
CREATE EXTENSION if not exists ltree ;