Skip to content

Commit

Permalink
Combine octane and nginx containers to deploy on Cloud Run
Browse files Browse the repository at this point in the history
  • Loading branch information
danieltrolezi committed Oct 6, 2024
1 parent e94a220 commit 4853eb1
Show file tree
Hide file tree
Showing 16 changed files with 479 additions and 294 deletions.
27 changes: 10 additions & 17 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,14 @@ jobs:
- name: Configure Docker to use Artifact Registry
run: gcloud auth configure-docker ${{ vars.GCP_REGION }}-docker.pkg.dev

- name: Build Docker image (Octane)
run: docker build . --file Dockerfile.app --tag octane:latest
- name: Build Docker image
run: docker build . --file Dockerfile --tag app:latest

- name: Build Docker image (Nginx)
run: docker build . --file Dockerfile.nginx --tag nginx:latest
- name: Tag Docker image
run: docker tag app:latest ${{ vars.GCP_AR_REPOSITORY }}/app:latest

- name: Tag Docker images
run: |
docker tag octane:latest ${{ vars.GCP_AR_REPOSITORY }}/octane:latest
docker tag nginx:latest ${{ vars.GCP_AR_REPOSITORY }}/nginx:latest
- name: Push Docker images to Artifact Registry
run: |
docker push ${{ vars.GCP_AR_REPOSITORY }}/octane:latest
docker push ${{ vars.GCP_AR_REPOSITORY }}/nginx:latest
- name: Push Docker image to Artifact Registry
run: docker push ${{ vars.GCP_AR_REPOSITORY }}/app:latest

cr-service-deploy:
runs-on: ubuntu-latest
Expand All @@ -57,10 +50,10 @@ jobs:

- name: Update Cloud Run Service definition
run: |
sed -i 's|<GCP_PROJECT_ID>|${{ vars.GCP_PROJECT_ID }}|' ./gcp/cloud-run/service.yaml
sed -i 's|<GCP_PROJECT_NUMBER>|${{ vars.GCP_PROJECT_NUMBER }}|' ./gcp/cloud-run/service.yaml
sed -i 's|<GCP_CLOUD_RUN_SERVICE>|${{ vars.GCP_CLOUD_RUN_SERVICE }}|' ./gcp/cloud-run/service.yaml
sed -i 's|<DOCKER_IMAGE_OCTANE>|${{ vars.GCP_AR_REPOSITORY }}/octane:latest|' ./gcp/cloud-run/service.yaml
sed -i 's|<DOCKER_IMAGE_NGINX>|${{ vars.GCP_AR_REPOSITORY }}/nginx:latest|' ./gcp/cloud-run/service.yaml
sed -i 's|<GCP_REGION>|${{ vars.GCP_AR_REPOSITORY }}/app:latest|' ./gcp/cloud-run/service.yaml
sed -i 's|<DOCKER_IMAGE>|${{ vars.GCP_AR_REPOSITORY }}/app:latest|' ./gcp/cloud-run/service.yaml
- name: Set up Google Cloud authentication
uses: google-github-actions/auth@v1
Expand All @@ -75,4 +68,4 @@ jobs:
export_default_credentials: true

- name: Deploy to Cloud Run
run: gcloud run services replace ./gcp/cloud-run/service.yaml --region ${{ vars.GCP_REGION }}
run: gcloud run services replace ./gcp/cloud-run/service.yaml --project ${{ vars.GCP_PROJECT_ID }} --region ${{ vars.GCP_REGION }}
5 changes: 1 addition & 4 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,5 @@ jobs:
- uses: actions/checkout@v4

- name: Build Docker image (Octane)
run: docker build . --file Dockerfile.app --tag ${{ vars.DOCKER_IMAGE_TAG }}/octane

- name: Build Docker image (Nginx)
run: docker build . --file Dockerfile.nginx --tag ${{ vars.DOCKER_IMAGE_TAG }}/nginx
run: docker build . --file Dockerfile --tag app:latest

25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM southamerica-east1-docker.pkg.dev/codelab92/php/8.3-swoole:latest

ARG APP_ENV=production
ENV APP_ENV=${APP_ENV}

WORKDIR /var/www/gamewatch

COPY . /var/www/gamewatch
COPY ./docker/php "${PHP_INI_DIR}/conf.d/"
COPY ./docker/supervisor /etc/supervisor/
COPY ./docker/nginx/default.conf /etc/nginx/conf.d/

RUN if [ "$APP_ENV" = "local" ]; then \
apt-get update && apt-get install -y nano npm; \
fi

#RUN find /var/www/gamewatch -not -path "/var/www/gamewatch/vendor/*" -type f -exec chmod 644 {} \; \
# && find /var/www/gamewatch -type d -exec chmod 755 {} \; \
# && chown -R www-data:www-data /var/www/gamewatch \
# && chmod -R ug+rwx storage bootstrap/cache

COPY ./docker/entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh

ENTRYPOINT ["entrypoint.sh"]
17 changes: 0 additions & 17 deletions Dockerfile.app

This file was deleted.

8 changes: 0 additions & 8 deletions Dockerfile.nginx

This file was deleted.

30 changes: 8 additions & 22 deletions docker-compose.yml
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,44 +1,30 @@
services:
octane:
container_name: octane
app:
container_name: app
build:
context: .
dockerfile: Dockerfile.app
args:
APP_ENV: ${APP_ENV}
env_file:
- .env
extra_hosts:
- "host.docker.internal:host-gateway"
ports:
- '80:80'
volumes:
- .:/srv/gamewatch
- ./vendor:/srv/gamewatch/vendor
working_dir: /srv/gamewatch
- .:/var/www/gamewatch
- ./vendor:/var/www/gamewatch/vendor
working_dir: /var/www/gamewatch
depends_on:
mysql:
condition: service_healthy
healthcheck:
test: ["CMD", "php", "artisan", "octane:status"]
test: ["CMD", "curl", "-f", "http://localhost/api/up"]
interval: 5s
timeout: 10s
retries: 5
networks:
- bridge

nginx:
container_name: nginx
build:
context: .
dockerfile: Dockerfile.nginx
environment:
- PHP_UPSTREAM_HOST=octane
ports:
- '80:80'
depends_on:
octane:
condition: service_healthy
networks:
- bridge

redis:
container_name: ${REDIS_HOST}
Expand Down
5 changes: 0 additions & 5 deletions docker/entrypoint.nginx.sh

This file was deleted.

6 changes: 4 additions & 2 deletions docker/entrypoint.app.sh → docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ fi
case "$RUN_MODE" in
octane)
if [ "$APP_ENV" == "local" ]; then
php artisan octane:swoole --host=0.0.0.0 --watch
cp /etc/supervisor/conf.d/octane.dev /etc/supervisor/conf.d/octane.conf
else
php artisan octane:swoole --host=0.0.0.0 --workers=4 --task-workers=4
cp /etc/supervisor/conf.d/octane.prod /etc/supervisor/conf.d/octane.conf
fi

supervisord -c /etc/supervisor/supervisord.conf
;;
notif)
php artisan app:dispatch-notifications
Expand Down
4 changes: 2 additions & 2 deletions docker/nginx/default.conf
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ map $http_upgrade $connection_upgrade {
}

upstream php_upstream {
server ${PHP_UPSTREAM_HOST}:8000;
server 127.0.0.1:8000;
}

server {
listen 80;
listen [::]:80;
server_name gamewatch;
server_name localhost gamewatch.local;
server_tokens off;
root /var/www/gamewatch/public;

Expand Down
31 changes: 0 additions & 31 deletions docker/php-fpm/www.conf

This file was deleted.

9 changes: 9 additions & 0 deletions docker/supervisor/conf.d/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[program:nginx]
command=/usr/sbin/nginx -g 'daemon off;'
autostart=true
autorestart=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes = 0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes = 0
exitcodes=0
10 changes: 10 additions & 0 deletions docker/supervisor/conf.d/octane.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[program:octane-dev]
command=php artisan octane:swoole --watch
autostart=true
autorestart=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes = 0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes = 0
exitcodes=0
priority=10
10 changes: 10 additions & 0 deletions docker/supervisor/conf.d/octane.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[program:octane-prod]
command=php artisan octane:swoole --workers=4 --task-workers=4
autostart=true
autorestart=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes = 0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes = 0
exitcodes=0
priority=10
23 changes: 23 additions & 0 deletions docker/supervisor/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[unix_http_server]
file=/var/run/supervisor.sock
chmod=0700
chown=www-data:www-data

[supervisord]
logfile=/dev/null
logfile_maxbytes=0
loglevel=info
pidfile=/var/run/supervisord.pid
nodaemon=true
minfds=1024
minprocs=200
user=root

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///var/run/supervisor.sock

[include]
files = /etc/supervisor/conf.d/*.conf
Loading

0 comments on commit 4853eb1

Please sign in to comment.