3

I'm trying to deploy an app from a docker-compose file with two images in it: an Angular app (frontend) and a very small nestjs app (backend). I'm using GCB, their triggers and a cloudbuild.json.

This is its current state:

{
  "steps": [
    {
      "name": "gcr.io/$PROJECT_ID/docker-compose",
      "args": ["-f", "./docker-compose.${_ENVIRONMENT}.yml", "up", "-d"]
    },
    {
      "name": "gcr.io/cloud-builders/docker",
      "args": ["tag", "configurator:latest", "gcr.io/$PROJECT_ID/${_IMAGE_ID}"]
    },
    {
      "name": "gcr.io/cloud-builders/gcloud",
      "args": [
        "run", "deploy",
        "--allow-unauthenticated",
        "${_IMAGE_ID}",
        "--image", "gcr.io/$PROJECT_ID/${_IMAGE_ID}",
        "--region", "europe-west4",
        "--platform", "managed"
      ]
    }
  ],
  "images": [
    "gcr.io/$PROJECT_ID/${_IMAGE_ID}"
  ],
  "timeout": "1200s"
}

The build always fails on step 2, when trying to push the docker image to the registry. I'm not really sure what the images name could be or how this should even work, since there is two docker images that need to be pushed and deployed. Is it even possible with GCB or do I need a GKE Cluster for running two docker images?

Should I maybe build the two Docker images separately, push them each to the registry and deploy them to separate GCR Services?

Thanks in advance.

chrnx
  • 444
  • 1
  • 3
  • 17

1 Answers1

3

Docker compose build nothing, it only run the images according with the yaml configuration. Your step 2, that tag something, tag what? That's why it fails.

So, forget docker compose. Deploy your backend on Cloud Run, only the container. For your frontend, you have several solution:

  • Deploy it on Cloud Run also (not the best solution)
  • Deploy the static files on App Engine (need to create a app.yaml file)
  • Deploy the static files on Google Cloud Storage.

then, create a load balancer with 2 backends:

  1. Your web site backend
  2. Your nestjs backend.

And then, you have a production ready deployment. (Let me know if you need more help on some parts)


EDIT 1

With a load balancer, you can define the path to serve your resources (URL map). For instances:

  • /nest/* -> redirect the traffic to your nestjs backend
  • /* -> by default, redirect the traffic to your bucket backend.

Both, static and nestjs backend, are accessible through the same IP (and domain name, after the set up of your DNS registrar. Google can also automatically provision the SSL certificate for you).

There is 2 advantages to use a Load balancer:

  • The front and the back have the same base URL, you won't have to manage CORS on your backend.
  • The traffic of both back and front is served in HTTP (not recommended) or HTTPS, that prevent the errors for mixed content in your browser.

Note: without a load balancer, you can serve static source only in HTTP mode, HTTPS isn't supported without additional layer, such as a load balancer.

The "issue" with a load balancer, is a minimal cost of $15 per month.

guillaume blaquiere
  • 66,369
  • 2
  • 47
  • 76
  • The app engine seems a little too expensive for my use case. How exactly would I access the actual app if I were to deploy it on Google Cloud Storage? Like what would the URL be then (hypothetically)? – chrnx Jan 31 '21 at 12:40
  • Or rather how to I serve that static content? – chrnx Jan 31 '21 at 12:47
  • App Engine standard serve for free static content (similar to firebase hosting). However, if you deploy your backend on App Engine, a container, you will use APp Engine Flex, and yes it's quite too expensive. – guillaume blaquiere Jan 31 '21 at 12:52
  • I updated my answer. I don't know if it's clear enough? – guillaume blaquiere Jan 31 '21 at 12:59
  • Yes, thanks for clarifying. I'll give it a try now! – chrnx Jan 31 '21 at 13:08
  • I've asked another related question, if you were so kind to take a look at it: https://stackoverflow.com/questions/66006531/google-cloud-app-engine-deploy-multiple-environments – chrnx Feb 02 '21 at 09:05