Skip to content

Instantly share code, notes, and snippets.

@einnar82
Last active April 15, 2021 08:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save einnar82/b61355a493a6dde0b82e0153fa76001b to your computer and use it in GitHub Desktop.
Save einnar82/b61355a493a6dde0b82e0153fa76001b to your computer and use it in GitHub Desktop.
Dockerized Stateless Laravel Application in Cloud Run
image: docker:latest
stages:
- deploy
deploy:
stage: deploy
image: google/cloud-sdk
services:
- docker:dind
script:
- echo $PROD_GCP_SERVICE_KEY > gcloud-service-key.json; # Google Cloud service accounts
- gcloud auth activate-service-account --key-file gcloud-service-key.json
- gcloud config set project $PROD_GCP_PROJECT_ID
- gcloud builds submit . --config=cloudbuild.yaml
when: manual
only:
- develop
- develop-reymar
steps:
# build the container image
- name: "gcr.io/cloud-builders/docker"
args:
[
"build",
"-t",
"gcr.io/$PROJECT_ID/health-monitoring-api:develop",
"-f",
"./Dockerfile.dev",
".",
]
# push the container image
- name: "gcr.io/cloud-builders/docker"
args: ["push", "gcr.io/$PROJECT_ID/health-monitoring-api:develop"]
# deploy to Cloud Run
- name: "gcr.io/cloud-builders/gcloud"
args:
[
"run",
"deploy",
"prod-ui-health-api-app",
"--image",
"gcr.io/$PROJECT_ID/health-monitoring-api:develop",
"--region",
"asia-southeast1",
"--platform",
"managed",
"--port",
"82",
"--allow-unauthenticated",
"--concurrency",
"250",
"--add-cloudsql-instances",
"petnet-core-app-prod-1:asia-southeast1:prod-core-app-db-1",
"--vpc-connector",
"projects/petnet-host-net-1/locations/asia-southeast1/connectors/petnet-coreapp-prod-con-1",
]
FROM php:7.2-fpm-alpine
RUN apk add --no-cache nginx wget
RUN docker-php-source extract \
&& curl -L -o /tmp/redis.tar.gz https://github.com/phpredis/phpredis/archive/3.0.0.tar.gz \
&& tar xfz /tmp/redis.tar.gz \
&& rm -r /tmp/redis.tar.gz \
&& mv phpredis-3.0.0 /usr/src/php/ext/redis
# Clear cache
RUN rm -rf /var/cache/apk/*
# Install extensions
# Make it readable and arrange from A-Z
RUN docker-php-ext-install \
bcmath \
exif \
mbstring \
pdo \
pdo_mysql \
pcntl \
redis
RUN mkdir -p /run/nginx
COPY docker/nginx.conf /etc/nginx/nginx.conf
RUN mkdir -p /app
COPY . /app
RUN sh -c "wget http://getcomposer.org/composer.phar && chmod a+x composer.phar && mv composer.phar /usr/local/bin/composer"
RUN cd /app && \
/usr/local/bin/composer install --no-dev
COPY .env.example /app/.env
RUN chown -R www-data: /app
RUN chmod 775 -R /app/storage
RUN php /app artisan migrate --seed
CMD sh /app/docker/startup.sh
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
sendfile on;
keepalive_timeout 65;
server {
listen LISTEN_PORT default_server;
server_name _;
root /app/public;
index index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico {
access_log off; log_not_found off;
}
location = /robots.txt {
access_log off; log_not_found off;
}
access_log /dev/stdout;
error_log /dev/stderr;
sendfile off;
client_max_body_size 100m;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 0.0.0.0:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
daemon off;
#!/bin/sh
sed -i "s,LISTEN_PORT,$PORT,g" /etc/nginx/nginx.conf
php-fpm -D
while ! nc -w 1 -z 0.0.0.0 9000; do sleep 0.1; done;
nginx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment