From c7860c66118c59d80bd7bea9863d6923c48b581e Mon Sep 17 00:00:00 2001 From: Rohan Sircar Date: Thu, 15 Apr 2021 20:18:17 +0530 Subject: [PATCH] temp commit --- .github/workflows/build.yaml | 53 ++++++++++++++++++++++++++--- build.sbt | 3 -- build.sh | 3 +- scripts/db.sh | 2 +- src/main/resources/application.conf | 9 ++++- 5 files changed, 59 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 8a8d293..666cf69 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -1,18 +1,61 @@ -name: Build +name: PostgreSQL service example on: push jobs: + # Label of the container job build: + # Containers must run in Linux based operating systems runs-on: ubuntu-latest + # Docker Hub image that `container-job` executes in + container: node:12-buster + env: + # The hostname used to communicate with the PostgreSQL service container + CODEGEN_DB_HOST: postgres + # The default PostgreSQL port + CODEGEN_DB_PORT: 5435 + CODEGEN_DB_USER: codegenuser + CODEGEN_DB_PASSWOD: postgres + CODEGEN_DB_NAME: codegendb + + # Service containers to run with `container-job` + services: + # Label used to access the service container + postgres: + # Docker Hub image + image: postgres + # Provide the password for postgres + env: + POSTGRES_PASSWORD: postgres + POSTGRES_USER: codegenuser + POSTGRES_DB: codegendb + port: + - 5435:5432 + # Set health checks to wait until postgres has started + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + steps: - - name: Checkout + # Downloads a copy of the code in your repository before running CI tests + - name: Check out repository code uses: actions/checkout@v2 + # - name: Coursier cache # uses: coursier/cache-action@v6 - name: Setup uses: olafurpg/setup-scala@v10 with: java-version: adopt@1.11 - # - run: sbt compile - # - run: sbt test - - run: ./build.sh + # - name: Connect to PostgreSQL + # # Runs a script that creates a PostgreSQL client, populates + # # the client with data, and retrieves data + # run: node client.js + - name: Migrate + run: csbt flyway/flywayMigrate + - name: Run Tests + run: csbt test + - name: Package + run: csbt docker:stage + # Environment variable used by the `client.js` script to create a new PostgreSQL client. diff --git a/build.sbt b/build.sbt index 566dbf7..dd18ca2 100644 --- a/build.sbt +++ b/build.sbt @@ -45,11 +45,8 @@ lazy val root = (project in file(".")) name := "http4s-demo", version := "0.0.1-SNAPSHOT", version in Docker := "0.0.1", - dockerExposedPorts ++= Seq(9000, 9001), dockerBaseImage := "openjdk:11-slim", dockerUsername := Some("rohansircar"), - // dockerVe - // dockerRepository := "" scalacOptions ++= Seq( "-encoding", "UTF-8", diff --git a/build.sh b/build.sh index 9609206..3827461 100755 --- a/build.sh +++ b/build.sh @@ -16,7 +16,8 @@ echo "Container id is $cid" sleep 5s # ./wait-for-it.sh localhost:5434 -s -t 300 -- echo "db started" sbtn flyway/flywayMigrate -sbtn docker:publishLocal +# needs docker login +sbtn docker:publish sbtn shutdown docker stop $cid diff --git a/scripts/db.sh b/scripts/db.sh index 23e15e8..11dea19 100644 --- a/scripts/db.sh +++ b/scripts/db.sh @@ -3,4 +3,4 @@ docker run \ -e POSTGRES_USER=test_user \ -e POSTGRES_PASSWORD=password \ -p 5433:5432 \ -postgres:12 \ No newline at end of file +-d postgres:12 \ No newline at end of file diff --git a/src/main/resources/application.conf b/src/main/resources/application.conf index dca3818..c3f2231 100644 --- a/src/main/resources/application.conf +++ b/src/main/resources/application.conf @@ -2,7 +2,14 @@ myapp = { database = { driver = org.postgresql.Driver - url = "jdbc:postgresql://localhost:5432/test_db" + # url = "jdbc:postgresql://localhost:5432/test_db" + dbHost = localhost + dbHost = ${?APP_DB_HOST} + dbPort = 5432 + dbPort = ${?APP_DB_PORT} + dbName = test_db + dbName = ${?APP_DB_NAME} + url = "jdbc:postgresql://"${myapp.database.dbHost}":"${myapp.database.dbPort}"/"${myapp.database.dbName} user = "test_user" password = "password"