Skip to content

Commit

Permalink
actions: Add postgres db to test job and migrate the db
Browse files Browse the repository at this point in the history
This commit adds a postgres db to test job and migrate the db.

Signed-off-by: Cosmin Tupangiu <[email protected]>
  • Loading branch information
tupyy committed Nov 6, 2024
1 parent 67bb991 commit c6736e7
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ on: # yamllint disable-line rule:truthy
jobs:
test:
runs-on: ubuntu-latest
env:
PGHOST: localhost
PGDATABASE: planner
PGUSERNAME: admin
PGPASSWORD: adminpass
steps:
- uses: actions/checkout@v4

Expand All @@ -20,11 +25,43 @@ jobs:
sudo apt update
sudo apt install libvirt-dev
- name: Add PostgreSQL binaries to PATH
shell: bash
run: |
echo "$(pg_config --bindir)" >> $GITHUB_PATH
- name: Start preinstalled PostgreSQL
shell: bash
run: |
echo "Initializing database cluster..."
# Convert backslashes to forward slashes in RUNNER_TEMP for Windows Git Bash
export PGHOST="${RUNNER_TEMP//\\//}/postgres"
export PGDATA="$PGHOST/pgdata"
mkdir -p "$PGDATA"
# initdb requires file for password in non-interactive mode
export PWFILE="$RUNNER_TEMP/pwfile"
echo "postgres" > "$PWFILE"
initdb --pgdata="$PGDATA" --username="postgres" --pwfile="$PWFILE"
echo "Starting PostgreSQL..."
echo "unix_socket_directories = '$PGHOST'" >> "$PGDATA/postgresql.conf"
pg_ctl start
echo "Creating user..."
psql --host "$PGHOST" --username="postgres" --dbname="postgres" --command="CREATE USER $PGUSERNAME PASSWORD '$PGPASSWORD'" --command="\du"
echo "Creating database..."
createdb --owner="$PGUSERNAME" --username="postgres" "$PGDATABASE"
- name: Prepare
run: |
make generate
DOWNLOAD_RHCOS=false make build
- name: Migrate the db
run: |
make migrate
- name: Test
run: |
make test
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ tidy:
lint: tools
$(GOBIN)/golangci-lint run -v --timeout 2m

migrate:
./bin/planner-api migrate --config $(PWD)/test/config.yaml

image:
ifeq ($(DOWNLOAD_RHCOS), true)
curl --silent -C - -O https://mirror.openshift.com/pub/openshift-v4/dependencies/rhcos/latest/rhcos-live.x86_64.iso
Expand Down
13 changes: 13 additions & 0 deletions test/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
database:
hostname: localhost
name: planner
password: adminpass
port: 5432
type: pgsql
user: admin
service:
address: :3443
agentEndpointAddress: :7443
baseAgentEndpointUrl: https://localhost:7443
baseUrl: https://localhost:3443
logLevel: info

0 comments on commit c6736e7

Please sign in to comment.