0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Cloudbuildを使ってCloud runにデプロイする

Posted at

まず

gcloud init

gcloud services enable artifactregistry.googleapis.com cloudbuild.googleapis.com run.googleapis.com

gcloud artifacts repositories create my-repo \
  --repository-format=docker \
  --location=asia-northeast1  \
  --description="Docker repository for Cloud Run"

次にPHPファイルとDocekerfileとcloudbuild.yamlを用意

index.php
<?php
echo "Hello, Artifact Registry and Cloud Run!";
Dockerfile.yaml
FROM php:8.2-apache

# Set the working directory inside the container
WORKDIR /var/www/html

# Copy application files to the container
COPY . /var/www/html

# Expose port 8080
EXPOSE 8080

# Update the Apache configuration to listen on port 8080
RUN sed -i 's/80/8080/' /etc/apache2/ports.conf \
    && sed -i 's/:80/:8080/' /etc/apache2/sites-available/000-default.conf

# Install additional PHP extensions if needed
RUN docker-php-ext-install pdo pdo_mysql

# Enable Apache mod_rewrite if needed
RUN a2enmod rewrite

# Restart Apache
CMD ["apache2-foreground"]

cloudbuild.yaml
steps:
  # Dockerイメージをビルド
  - name: 'gcr.io/cloud-builders/docker'
    args: [
      'build', '-t',
      'asia-northeast1-docker.pkg.dev/$PROJECT_ID/my-repo/php-cloud-run-example',
      '.'
    ]

  # DockerイメージをArtifact Registryにプッシュ
  - name: 'gcr.io/cloud-builders/docker'
    args: [
      'push',
      'asia-northeast1-docker.pkg.dev/$PROJECT_ID/my-repo/php-cloud-run-example'
    ]

  # Cloud Runにデプロイ
  - name: 'gcr.io/cloud-builders/gcloud'
    args: [
      'run', 'deploy', 'php-cloud-run-example',
      '--image',
      'asia-northeast1-docker.pkg.dev/$PROJECT_ID/my-repo/php-cloud-run-example',
      '--region', 'asia-northeast1',
      '--platform', 'managed',
      '--allow-unauthenticated'
    ]

images:
  - 'asia-northeast1-docker.pkg.dev/$PROJECT_ID/my-repo/php-cloud-run-example'

あとは
gcloud config set project プロジェクト名

gcloud builds submit --config cloudbuild.yaml .

これでbuild実行!!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?