{"id":18941496,"url":"https://github.com/mchmarny/logo-identifier","last_synced_at":"2026-03-23T21:30:18.125Z","repository":{"id":77051673,"uuid":"202016978","full_name":"mchmarny/logo-identifier","owner":"mchmarny","description":"Simple logo identification service demonstrating use of Cloud SQL and Google Vision API in Cloud Run.","archived":false,"fork":false,"pushed_at":"2020-01-24T23:25:18.000Z","size":21722,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-08-10T11:04:01.424Z","etag":null,"topics":["cloudrun","cloudsql","custom-metrics","golang","sql","stackdriver","vision-api"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mchmarny.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-08-12T22:14:12.000Z","updated_at":"2024-06-19T07:45:21.478Z","dependencies_parsed_at":null,"dependency_job_id":"3579f1b1-cbf2-4da9-acea-9ec32b66dd9a","html_url":"https://github.com/mchmarny/logo-identifier","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mchmarny%2Flogo-identifier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mchmarny%2Flogo-identifier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mchmarny%2Flogo-identifier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mchmarny%2Flogo-identifier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mchmarny","download_url":"https://codeload.github.com/mchmarny/logo-identifier/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239942722,"owners_count":19722330,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloudrun","cloudsql","custom-metrics","golang","sql","stackdriver","vision-api"],"created_at":"2024-11-08T12:28:16.990Z","updated_at":"2026-03-23T21:30:18.083Z","avatar_url":"https://github.com/mchmarny.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# logo-identifier\n\nSimple logo identification service demonstrating use of Cloud SQL and Google Vision API in Cloud Run.\n\nDemo: https://logoider-2gtouos2pq-uc.a.run.app\n\n## Why\n\nSetting up development and deployment pipeline for Cloud Run service backed by project-level authenticated services like Cloud Vision and connection string based authenticated ones like Cloud SQL can be complicated. While logo identification is probably not representative of a real production workload, this simple service does illustrate all of the aspects of local development and service deployment on Cloud Run.\n\n## Pre-requirements\n\n### GCP Project and gcloud SDK\n\nIf you don't have one already, start by creating new project and configuring [Google Cloud SDK](https://cloud.google.com/sdk/docs/). Similarly, if you have not done so already, you will have [set up Cloud Run](https://cloud.google.com/run/docs/setup).\n\n## Setup\n\nTo setup this service you will need to:\n\n* Configure service dependencies\n* Build docker image from the source in this repo\n* Deploy and configure service using the previously built image\n\nTo start, clone this repo:\n\n```shell\ngit clone https://github.com/mchmarny/logo-identifier.git\n```\n\nAnd navigate into that directory:\n\n```shell\ncd logo-identifier\n```\n\n### Configure Dependencies\n\nIn this section you will:\n\n* Enable required GCP APIs\n* Create Cloud SQL instance and configure it with database and user\n* Create a Service Account and configure it with required IAM policies\n* Configure OAuth credentials with Cloud Run service callback URL\n\n#### APIs\n\nFirst, let's ensure all the required GCP APIs are enabled. To do that, run the [bin/setup](./bin/setup) script:\n\n\u003e Note, to keep this readme short, I will be asking you to execute scripts rather than listing here complete commands. You should really review each one of these scripts for content, and, to understand the individual commands so you can use them in the future.\n\n\n```shell\nbin/setup\n```\n\n#### DB\n\nBefore creating Cloud SQL instance, you'll need to define a couple of passwords: default DB user (`root`), and the application specific user (`logoider-db-user`). To do that we will use the `openssl` command line utility. If for some reason you do not have `openssl` configured, you can just set these value to your own secrets.\n\n```shell\nexport DB_ROOT_SECRET=$(openssl rand -base64 16)\necho \"root user password: ${DB_ROOT_SECRET}\"\nexport DB_USER_SECRET=$(openssl rand -base64 16)\necho \"app user password: ${DB_USER_SECRET}\"\n```\n\nTo create `logoider` CLoud SQL instance, run [bin/db](./bin/db) script:\n\n```shell\nbin/db\n```\n\nOne Cloud SQL finished configuring, there number you can [connect to your newly created instance](https://cloud.google.com/sql/docs/mysql/external-connection-methods). The by-far easiest is Cloud Shell. Navigate to [Cloud Shell](https://console.cloud.google.com/) and Connect to your instance:\n\n```shell\ngcloud sql connect logoider --user=root --quiet\n```\n\nYou will see a message about whitelisting your IP for incoming connection. Just wait until that's finished and when finally prompted for `root` password enter the value `$DB_ROOT_SECRET`.\n\n\u003e You can print it out in the console where you run original setup `echo DB_ROOT_SECRET`\n\nThat will get you to MySQL prompt in Cloud Shell:\n\n```shell\nMySQL [(none)]\u003e\n```\n\nTo create and configure your database schema, review and copy the entire [schema.ddl](sql/schema.ddl) file, paste it into the Cloud Shell window, and hit enter. You should see SQL output with 4 `Query OK` entries. You can now close the Cloud Shell window.\n\n#### IAM\n\nTo ensure that your Cloud RUn service is able to do only the intended tasks and nothing more, you will create a service account which will be used to run the Cloud Run service and configure it with a few explicit roles:\n\n* `run.invoker` - required to execute Cloud Run service\n* `cloudsql.editor` - required to connect and write/read/delete on Cloud SQL\n* `logging.logWriter` - required for Stackdriver logging\n* `cloudtrace.agent` - required for Stackdriver tracing\n* `monitoring.metricWriter` - required to write custom metrics to Stackdriver\n\nTo create and configure `logoider-sa` service account, run [bin/user](./bin/user) script:\n\n```shell\nbin/user\n```\n\n#### OAuth (chicken and an egg)\n\nCloud Run service URLs are not currently predictable. To deploy Cloud Run service you will need the OAuth credentials. To configure those credentials, you will need a callback URL that includes the Cloud Run service URL. You can see the chicken and an egg situation here. To work around it, we will deploy service first and then come back here and update the OAuth settings.\n\n### Build Container Image\n\nCloud Run runs container images. To build one for this service we are going to use the included [Dockerfile](./Dockerfile) and submit it along with the source code as a build job to Cloud Build using [bin/image](./bin/image) script.\n\n```shell\nbin/image\n```\n\n### Deploy the Cloud Run Service\n\nOnce you have configured all the service dependencies, we can now deploy your Cloud Run service. To do that run [bin/service](./bin/service) script:\n\n```shell\nbin/service\n```\n\nThe output of the script will include the URL by which you can access that service.\n\n### OAuth\n\nOAuth credentials have to be set up manually. In your Google Cloud Platform (GCP) project console navigate to the Credentials section. You can use the search bar, just type `Credentials` and select the option with \"API \u0026 Services\". To create new OAuth credentials:\n\n* Click “Create credentials” and select “OAuth client ID”\n* Select \"Web application\"\n* Add authorized redirect URL at the bottom using the fully qualified domain we defined above and appending the `callback` path:\n * `https://[SERVICE_URL]/auth/callback`\n* Click create and copy both `client id` and `client secret`\n* CLICK `OK` to save\n\nFor ease of use, export the copied client `id` as `LI_OAUTH_CLIENT_ID` and `secret` as `LI_OAUTH_CLIENT_SECRET`\n\n```shell\nexport LI_OAUTH_CLIENT_ID=\"\"\nexport LI_OAUTH_CLIENT_SECRET=\"\"\n```\n\n\u003e You will also have to add the service URL to Authorized Domains section on the OAuth consent screen. More on that [here](https://support.google.com/cloud/answer/6158849?hl=en#authorized-domains)\n\n### Deploy the Cloud Run Service (agin)\n\nTo finish configuring our service we will need to create a new Cloud Run service revision. The easiest way to do that is to redeploy the service again using the same [bin/service](./bin/service) script:\n\n```shell\nbin/service\n```\n\n## Usage\n\nYou can access the The Icon Identifier application by navigating to the deployed Cloud Run service URL. You can run the [bin/url](./bin/url) script to print it out again\n\n```shell\nbin/url\n```\n\nOnce you access the deployed application:\n\n* Click on \"Sign in With Google\" and follow the OAuth prompts\n* Once authenticated, click on any of the provided logos (populates image URL)\n* Click \"Identify\" button to see it's description\n\n\u003e You can also use any other publicly accessible logo image by pasting its URL\n\n## Cleanup\n\nTo cleanup all resources created by this sample execute the [bin/cleanup](bin/cleanup) script.\n\n```shell\nbin/cleanup\n```\n\n## Disclaimer\n\nThis is my personal project and it does not represent my employer. I take no responsibility for issues caused by this code. I do my best to ensure that everything works, but if something goes wrong, my apologies is all you will get.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmchmarny%2Flogo-identifier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmchmarny%2Flogo-identifier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmchmarny%2Flogo-identifier/lists"}