Desplegar Spring Boot en Google Cloud Run con Cloud Build

Guía paso a paso para desplegar una aplicación Spring Boot en Google Cloud Run con Cloud Build, usando Artifact Registry y Docker multietapa, con buenas prácticas y monitoreo.

12 sept 2025 • 3 min read • Q2BSTUDIO Team

Inteligencia-Artificial-

Spring Boot es uno de los frameworks más populares para construir microservicios en Java. Con Google Cloud Run puedes desplegar tu aplicación Spring Boot en un entorno serverless totalmente gestionado sin preocuparte por aprovisionar servidores, escalado o gestión de infraestructura. A continuación se explica paso a paso cómo desplegar una aplicación Spring Boot en Cloud Run usando Cloud Build, con buenas prácticas y comandos para acelerar el proceso.

Requisitos previos Una cuenta de Google Cloud con facturación activada, Google Cloud SDK instalado localmente y una aplicación Spring Boot simple. Repositorio de ejemplo en GitHub https://github.com/lalamanil/IntegratingAccidentPredictionModelOfVideo.git

Paso 1 Verificar instalación de gcloud y configuración del proyecto Comprueba que la CLI de Google Cloud está disponible con gcloud --version. Verifica el proyecto activo con gcloud config get-value project y si hace falta establece el proyecto con gcloud config set project NOMBRE_DEL_PROYECTO. Opcional pero recomendado define la región y la zona por defecto con gcloud config set compute/region us-central1 y gcloud config set compute/zone us-central1-a

Paso 2 Habilitar las APIs necesarias Asegúrate de que los servicios requeridos estén habilitados. Lista servicios habilitados con gcloud services list --enabled. Si falta alguno habilítalo con gcloud services enable artifactregistry.googleapis.com gcloud services enable cloudbuild.googleapis.com gcloud services enable run.googleapis.com gcloud services enable compute.googleapis.com

Paso 3 Crear un repositorio en Artifact Registry Artifact Registry es el lugar recomendado para almacenar las imágenes Docker. Lista repositorios existentes con gcloud artifacts repositories list y crea uno nuevo con gcloud artifacts repositories create springboot-docker-repo --repository-format=docker --location=us-central1 --description=Docker repo for Spring Boot images Verifica de nuevo con gcloud artifacts repositories list

Paso 4 Añadir un Dockerfile multietapa al proyecto Spring Boot En la raíz de tu proyecto Spring Boot añade un Dockerfile multistage para optimizar tamaño y tiempos de construcción. Un Dockerfile multietapa permite compilar la aplicación en una etapa y empaquetarla en una imagen ligera en otra etapa, ideal para entornos serverless como Cloud Run

Paso 5 Construir y subir la imagen con Cloud Build En lugar de construir localmente puedes usar Cloud Build para compilar y subir la imagen directamente a Artifact Registry. Para comprobar imágenes en el repo usa gcloud artifacts docker images list us-central1-docker.pkg.dev/NOMBRE_DEL_PROYECTO/springboot-docker-repo Sustituye NOMBRE_DEL_PROYECTO por tu proyecto. Construye y sube con gcloud builds submit --tag=us-central1-docker.pkg.dev/NOMBRE_DEL_PROYECTO/springboot-docker-repo/cloudrunspringbootdeploy:v1 Este comando compila la imagen en Google Cloud, la etiqueta y la empuja al repositorio de Artifact Registry

Paso 6 Desplegar en Cloud Run Despliega el contenedor directamente desde Artifact Registry con gcloud run deploy springboot-service --image=us-central1-docker.pkg.dev/NOMBRE_DEL_PROYECTO/springboot-docker-repo/cloudrunspringbootdeploy:v1 --region=us-central1 --allow-unauthenticated Asegúrate de que tu aplicación Spring Boot expone un endpoint de salud por ejemplo /healthCheck para comprobar que el servicio responde desde el navegador o mediante curl. Revisa los logs en Cloud Run desde la consola de Google Cloud para depuración y escalado

Consejos prácticos y buenas prácticas escalables incluye configurar variables de entorno de forma segura mediante Secret Manager o configuraciones de Cloud Run, habilitar revisiones automáticas y pruebas en Cloud Build, y optimizar la imagen Docker con una etapa de construcción que genere un artefacto empaquetado y otra etapa basada en una imagen runtime ligera

Q2BSTUDIO es una empresa de desarrollo de software dedicada a crear soluciones a medida y aplicaciones a medida para clientes que buscan tecnología de vanguardia. Somos especialistas en inteligencia artificial, ciberseguridad, servicios cloud aws y azure, servicios de inteligencia de negocio y automatización de procesos. Si necesitas una app personalizada o asesoramiento en arquitecturas cloud visita nuestra página de desarrollo de aplicaciones y software a medida desarrollo aplicaciones y software multiplataforma o conoce nuestras soluciones de infraestructura en servicios cloud aws y azure

Palabras clave integradas para mejorar posicionamiento web incluyen aplicaciones a medida, software a medida, inteligencia artificial, ciberseguridad, servicios cloud aws y azure, servicios inteligencia de negocio, ia para empresas, agentes IA y power bi. En Q2BSTUDIO combinamos experiencia en IA para empresas, agentes IA y soluciones de business intelligence con herramientas como Power BI para ofrecer productos robustos y seguros adaptados a cada cliente

Si quieres que te ayudemos a desplegar tu proyecto Spring Boot en Cloud Run, optimizar contenedores, integrar pipelines de CI CD con Cloud Build o diseñar una arquitectura escalable contacta con Q2BSTUDIO y potencia tu estrategia digital con software a medida, seguridad y capacidades de inteligencia artificial

A BREAK?

Play for a moment before you go

OUR SERVICES

How we can help you

Artificial intelligence

AI agents, chatbots, and intelligent assistants that automate tasks and serve your customers 24/7 to improve the efficiency of your business.

More info

Software Development

Web, mobile, and desktop applications, intranets, e-commerce, SaaS, and management platforms designed for your company's specific needs.

More info

Cloud services

Migration, infrastructure, managed hosting, high availability, and security on Microsoft Azure and Amazon Web Services to help your business scale without limits.

More info

Cybersecurity and pentesting

Security audits, penetration testing and protection of applications, data and infrastructure on-premise and cloud, with ethical hacking and regulatory compliance.

More info

Business Intelligence

Dashboards and data analysis with Power BI: we integrate your sources, design dashboards and KPIs and turn your data into decisions.

More info

Process automation

We automate repetitive tasks and connect your applications with n8n, Power Automate, Make, and RPA, eliminating manual work and increasing productivity.

More info

Training for Companies

We train your teams in technology with criteria: web development, databases, Git, best practices and security, automation with n8n, artificial intelligence for companies and creation of AI solutions with Azure AI Foundry.

More info

Code Auditing

We audit the code that you, your team or an AI create: we tell you what is good and what to improve, we secure it and make it ready for production, web or app.

More info

AI Image Generation

We create for you the images that your business needs with artificial intelligence: product, networks, advertising, illustration and avatars. You tell us what you want and we deliver it ready to use.

More info

AI Video Generation

We create videos with artificial intelligence for you: promotional, networking, virtual presenters, dubbing and animations. You tell us the idea and we will deliver it assembled and ready to publish.

More info

AI Conversational Avatars

We create conversational avatars with AI – digital humans with a face and voice – that serve your customers and teams with the knowledge of your company, on your website, interactive monitors, WhatsApp or Teams.

More info

Online Marketing and AI

Google Ads, Meta Ads, LinkedIn Ads and AI Engine Positioning (GEO/AEO): we attract customers and make your brand appear where they search for you, also on ChatGPT, Gemini and Perplexity.

More info

Do you have a project in mind?

Tell us your vision and we'll turn it into a software solution. Whatever the scope, we make your idea real.

Live Chat