18. JSON
a.k.a API Mocking
—
val faker = Faker(Locale("..."))
val contacts = mutableListOf<Contact>()
for (i in 1..10) {
contacts.add(Contact(
id = i.toLong(),
name = faker.name().fullName(),
email = faker.internet().emailAddress(),
mobile = faker.phoneNumber().cellPhone(),
address = faker.address().fullAddress(),
createdAt = DateTime.now().toString("yyyy-MM-dd HH:mm:ss"),
updatedAt = DateTime.now().toString("yyyy-MM-dd HH:mm:ss")
))
}
call.respond(mapOf("data" to contacts))
20. Behind the Jib
—
Video source: https://www.youtube.com/watch?v=H6gR_Cv4yWI
Build containers faster with Jib, a Google image build tool for Java applications
27. cloudbuild.yaml
—
steps:
# Uses the Cloud Builders Gradle image.
- name: 'gcr.io/cloud-builders/gradle'
args:
# Uncomment for projects that do not include Jib as a plugin.
- '--init-script=auto-jib.gradle'
# Runs the Jib build.
# For advanced customizations, configure the plugin in the build.gradle.
- 'jib'
# Sets the target image reference to push to.
- '--image=gcr.io/${_PROJECT}/${_IMAGE}'
28. auto-jib.gradle
—
// Gradle init script that applies the Jib Gradle plugin.
initscript {
repositories {
maven {
url 'https://plugins.gradle.org/m2'
}
}
dependencies {
classpath 'gradle.plugin.com.google.cloud.tools:jib-gradle-plugin:+'
}
}
// Only applies the Jib plugin if the project does not apply it already.
rootProject {
afterEvaluate {
if (!project.plugins.hasPlugin('com.google.cloud.tools.jib')) {
project.apply plugin: com.google.cloud.tools.jib.gradle.JibPlugin
tasks.jib.dependsOn classes
}
}
}
29. cloudbuild.yaml
—
steps:
# Uses the Cloud Builders Gradle image.
...
# Deploy an image from Container Registry to Cloud Run
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
entrypoint: gcloud
args:
- 'run'
- 'deploy'
- '${_SERVICE}'
- '--image'
- 'gcr.io/${_PROJECT}/${_IMAGE}'
- '--region'
- '${_REGION}'
- '--platform'
- 'managed'
- '--allow-unauthenticated'