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

[risk=no] trying to make api dockerless #1272

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions public-api/db-cdr/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ buildscript {
apply plugin: 'org.liquibase.gradle'
apply plugin: 'application'

def db_host = System.getenv("DB_HOST") ?: "db"
def db_host = System.getenv("DB_HOST") ?: "127.0.0.1"
def db_port = System.getenv("DB_PORT") ?: "3306"
def db_name = System.getenv("CDR_DB_NAME") ?: "cdr"
def liquibase_password = System.getenv("LIQUIBASE_DB_PASSWORD") ?: "lb-notasecret"
Expand Down Expand Up @@ -53,4 +53,4 @@ liquibase {
}
runList = project.ext.runList
}
}
}
27 changes: 11 additions & 16 deletions public-api/db/build.gradle
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
plugins {
id 'org.liquibase.gradle' version '2.1.0'
}

repositories {
mavenCentral()
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.liquibase:liquibase-gradle-plugin:1.2.4'
classpath 'mysql:mysql-connector-java:5.1.37'
}
}
apply plugin: 'org.liquibase.gradle'

def db_host = System.getenv("DB_HOST") ?: "db"
def db_host = System.getenv("DB_HOST") ?: "127.0.0.1"
def db_port = System.getenv("DB_PORT") ?: "3306"
def liquibase_password = System.getenv("LIQUIBASE_DB_PASSWORD") ?: "lb-notasecret"

dependencies {
liquibaseRuntime 'org.liquibase:liquibase-core:3.10.0'
liquibaseRuntime 'org.liquibase:liquibase-groovy-dsl:3.0.0'
liquibaseRuntime 'info.picocli:picocli:4.6.1'
liquibaseRuntime 'mysql:mysql-connector-java:5.1.34'
liquibaseRuntime group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1'
}

liquibase {
activities {
main {
Expand All @@ -28,4 +23,4 @@ liquibase {
}
runList = project.ext.runList
}
}
}
116 changes: 1 addition & 115 deletions public-api/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,34 +1,6 @@

version: "3.4"

# x- indicates an "extension", so docker-compose will ignore the attribute. The
# name is not important, it's just the necessary syntax to create a YAML anchor
# for reuse across the below services.
x-api-defaults: &api-defaults
# This image label exists for documentation purposes only, e.g. to identify
# it via `docker images`. We do not actually push this image up to DockerHub.
# Since docker-compose should never find this image remotely, it will rebuild
# it from the provided build context or use a cached local version.
# When making changes to this image, you can modify this tag to force all devs
# to rebuild.
image: allofustest/workbench-dev-api:local-3
build:
context: ./src/dev/server
user: ${UID}
working_dir: /w/public-api
environment:
- GOOGLE_APPLICATION_CREDENTIALS=/w/public-api/sa-key.json
env_file:
- db/vars.env
volumes:
- db-sync:/w:nocopy
- gradle-cache:/.gradle
- ~/.config:/.config:cached
- ~/.gsutil:/.gsutil:cached

services:
scripts:
<<: *api-defaults
db:
image: mysql:5.7
platform: linux/amd64
Expand All @@ -39,91 +11,5 @@ services:
ports:
- 127.0.0.1:3306:3306

public-api:
<<: *api-defaults
command: ./gradlew :appengineRun
ports:
- 127.0.0.1:8083:8083
- 127.0.0.1:8084:8002

db-scripts:
<<: *api-defaults
depends_on:
- db
working_dir: /w/public-api/db
entrypoint: [ 'with-uid.sh', 'wait-for', 'db:3306', -- ]

api-scripts:
<<: *api-defaults
depends_on:
- db

cdr-scripts:
<<: *api-defaults
depends_on:
- db
working_dir: /w/public-api/db-cdr
entrypoint: [ 'with-uid.sh', 'wait-for', 'db:3306', -- ]

db-generate-public-cdr-counts:
<<: *api-defaults
depends_on:
- db
working_dir: /w/public-api/db-cdr
entrypoint: ["./generate-cdr/generate-public-cdr-counts.sh"]
env_file:
- db-cdr/vars.env

db-generate-cloudsql-db:
<<: *api-defaults
depends_on:
- db
working_dir: /w/public-api/db-cdr
entrypoint: ["./generate-cdr/generate-cloudsql-db.sh"]
env_file:
- db-cdr/vars.env

db-generate-local-cdr-db:
<<: *api-defaults
depends_on:
- db
working_dir: /w/public-api/db-cdr

entrypoint: ["./generate-cdr/generate-local-cdr-db.sh"]
env_file:
- db-cdr/vars.env

db-generate-local-count-dbs:
<<: *api-defaults
depends_on:
- db
working_dir: /w/public-api/db-cdr
entrypoint: ["./generate-cdr/generate-local-count-dbs.sh"]
env_file:
- db-cdr/vars.env

db-mysqldump-local-db:
<<: *api-defaults
depends_on:
- db
working_dir: /w/public-api/db-cdr
entrypoint: ["./generate-cdr/make-mysqldump.sh"]
env_file:
- db-cdr/vars.env

db-cloudsql-import:
<<: *api-defaults
working_dir: /w/public-api/db-cdr
entrypoint: ["./generate-cdr/cloudsql-import.sh"]

db-local-mysql-import:
<<: *api-defaults
working_dir: /w/public-api/db-cdr
entrypoint: ["./generate-cdr/local-mysql-import.sh"]

volumes:
db:
gradle-cache:
gradle-public-api-cache:
db-sync:
external: true
db:
44 changes: 37 additions & 7 deletions public-api/libproject/cloudsqlproxycontext.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,55 @@
require_relative "../../aou-utils/serviceaccounts"
require_relative "../../aou-utils/utils/common"
require_relative "../../aou-utils/workbench"

class CloudSqlProxyContext < ServiceAccountContext

def run()
common = Common.new
# TODO(dmohs): An error here does not cause the main thread to die.
super do
@ps = fork do
exec(*%W{
ps = nil
docker_container_id = nil
instance = "#{@project}:us-central1:databrowsermaindb=tcp:0.0.0.0:3307"
if Workbench.in_docker?
ps = fork do
exec(*%W{
cloud_sql_proxy
-instances #{@project}:us-central1:databrowsermaindb=tcp:0.0.0.0:3307
-instances #{instance}
-credential_file=#{@path}
})
})
end
else
docker_container_id = common.capture_stdout(%W{docker run -d
-u #{ENV["UID"]}
-v #{@keyfile_path}:/config
-p 0.0.0.0:3307:3307
gcr.io/cloudsql-docker/gce-proxy:1.19.1 /cloud_sql_proxy
-instances=#{instance}
-credential_file=/config
}).chomp
end
begin
sleep 1 # TODO(dmohs): Detect running better.
deadlineSec = 40

common.status "waiting up to #{deadlineSec}s for cloudsql proxy to start..."
start = Time.now
until (common.run %W{mysqladmin ping --host 0.0.0.0 --port 3307 --silent}).success?
if Time.now - start >= deadlineSec
raise("mysql docker service did not become available after #{deadlineSec}s")
end
sleep 1
end
yield
ensure
Process.kill "HUP", @ps
Process.wait
if ps
Process.kill "HUP", ps
Process.wait
else if docker_container_id
common.run_inline(%W{docker kill #{docker_container_id}})
end
end
end
end
end
end
Loading