From c10669c535495219704bdba92ba3fd35c4132ab2 Mon Sep 17 00:00:00 2001 From: Piotr Biernat Date: Tue, 23 Nov 2021 12:57:04 +0100 Subject: [PATCH 1/9] [feature] Build & publish dev tag after push to feature/* branch --- .drone.yml | 73 +++++++++++++++++++++++++++++-- src/etc/nginx/conf.d/default.conf | 7 ++- src/etc/supervisor.d/services.ini | 3 +- 3 files changed, 74 insertions(+), 9 deletions(-) diff --git a/.drone.yml b/.drone.yml index 6f45bbd..8ac9b05 100644 --- a/.drone.yml +++ b/.drone.yml @@ -4,17 +4,19 @@ type: docker name: Build steps: -- name: build +- name: build_release image: plugins/docker commands: - sleep 5 - docker build -t docker.pbiernat.dev/nginx-php . - docker images | grep nginx-php + when: + event: tag volumes: - name: docker-sock path: /var/run -- name: publish +- name: publish_release image: plugins/docker environment: DOCKER_USERNAME: @@ -26,7 +28,71 @@ steps: - docker login docker.pbiernat.dev -u $DOCKER_USERNAME -p $DOCKER_PASSWORD - docker push docker.pbiernat.dev/nginx-php when: - branch: master + event: tag + volumes: + - name: docker-sock + path: /var/run + +- name: build_develop + image: plugins/docker + commands: + - sleep 5 + - docker build -t docker.pbiernat.dev/nginx-php:dev . + - docker images --format "{{.Repository}}:{{.Tag}}" | grep nginx-php:dev + when: + branch: develop + event: pull_request + volumes: + - name: docker-sock + path: /var/run + +- name: publish_develop + image: plugins/docker + privileged: true + environment: + DOCKER_USERNAME: + from_secret: registry_username + DOCKER_PASSWORD: + from_secret: registry_password + commands: + - sleep 5 + - docker login docker.pbiernat.dev -u $DOCKER_USERNAME -p $DOCKER_PASSWORD + - docker push docker.pbiernat.dev/nginx-php:dev + when: + branch: develop + event: pull_request + volumes: + - name: docker-sock + path: /var/run + +- name: build_feature + image: plugins/docker + commands: + - sleep 5 + - docker build -t docker.pbiernat.dev/nginx-php:$CI_COMMIT_BRANCH . + - docker images --format "{{.Repository}}:{{.Tag}}" | grep nginx-php:${CI_COMMIT_BRANCH} + when: + branch: feature_* + event: push + volumes: + - name: docker-sock + path: /var/run + +- name: publish_feature + image: plugins/docker + privileged: true + environment: + DOCKER_USERNAME: + from_secret: registry_username + DOCKER_PASSWORD: + from_secret: registry_password + commands: + - sleep 5 + - docker login docker.pbiernat.dev -u $DOCKER_USERNAME -p $DOCKER_PASSWORD + - docker push docker.pbiernat.dev/nginx-php:$CI_COMMIT_BRANCH + when: + branch: feature_* + event: push volumes: - name: docker-sock path: /var/run @@ -42,4 +108,3 @@ services: volumes: - name: docker-sock temp: {} - diff --git a/src/etc/nginx/conf.d/default.conf b/src/etc/nginx/conf.d/default.conf index 76e5402..1228c2b 100644 --- a/src/etc/nginx/conf.d/default.conf +++ b/src/etc/nginx/conf.d/default.conf @@ -1,10 +1,8 @@ server { listen 80 default_server; - listen [::]:80 default_server; root /var/www/app/public; location / { - # try to serve file directly, fallback to index.php try_files $uri /index.php$is_args$args; } @@ -14,7 +12,7 @@ server { include fastcgi_params; # optionally set the value of the environment variables used in the application - # fastcgi_param APP_ENV prod; + fastcgi_param APP_ENV dev; # fastcgi_param APP_SECRET ; # fastcgi_param DATABASE_URL "mysql://db_user:db_pass@host:3306/db_name"; @@ -27,7 +25,8 @@ server { # for more information). fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; fastcgi_param DOCUMENT_ROOT $realpath_root; - # Prevents URIs that include the front controller. This will 404: + + # Prevents URIs that include the front controller. This will 404: # http://domain.tld/index.php/some-path # Remove the internal directive to allow URIs like this internal; diff --git a/src/etc/supervisor.d/services.ini b/src/etc/supervisor.d/services.ini index f7e4aaf..8b5e0ec 100644 --- a/src/etc/supervisor.d/services.ini +++ b/src/etc/supervisor.d/services.ini @@ -2,6 +2,7 @@ logfile=/var/log/supervisord.log pidfile=/var/run/supervisord.pid nodaemon=false +user=root [program:nginx] command=/usr/sbin/nginx -g 'daemon off;' @@ -21,4 +22,4 @@ priority=5 stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr -stderr_logfile_maxbytes=0 \ No newline at end of file +stderr_logfile_maxbytes=0 From 2b7821456b62c35681cc0dfb559b4dfc9cfeaf1d Mon Sep 17 00:00:00 2001 From: Piotr Biernat Date: Tue, 23 Nov 2021 12:57:04 +0100 Subject: [PATCH 2/9] [feature] Build & publish dev tag after push to feature/* branch --- .drone.yml | 73 +++++++++++++++++++++++++++++-- src/etc/nginx/conf.d/default.conf | 7 ++- src/etc/supervisor.d/services.ini | 3 +- 3 files changed, 74 insertions(+), 9 deletions(-) diff --git a/.drone.yml b/.drone.yml index 6f45bbd..6588302 100644 --- a/.drone.yml +++ b/.drone.yml @@ -4,17 +4,19 @@ type: docker name: Build steps: -- name: build +- name: build_release image: plugins/docker commands: - sleep 5 - docker build -t docker.pbiernat.dev/nginx-php . - docker images | grep nginx-php + when: + event: tag volumes: - name: docker-sock path: /var/run -- name: publish +- name: publish_release image: plugins/docker environment: DOCKER_USERNAME: @@ -26,7 +28,71 @@ steps: - docker login docker.pbiernat.dev -u $DOCKER_USERNAME -p $DOCKER_PASSWORD - docker push docker.pbiernat.dev/nginx-php when: - branch: master + event: tag + volumes: + - name: docker-sock + path: /var/run + +- name: build_develop + image: plugins/docker + commands: + - sleep 5 + - docker build -t docker.pbiernat.dev/nginx-php:dev . + - docker images --format "{{.Repository}}:{{.Tag}}" | grep nginx-php:dev + when: + branch: develop + event: pull_request + volumes: + - name: docker-sock + path: /var/run + +- name: publish_develop + image: plugins/docker + privileged: true + environment: + DOCKER_USERNAME: + from_secret: registry_username + DOCKER_PASSWORD: + from_secret: registry_password + commands: + - sleep 5 + - docker login docker.pbiernat.dev -u $DOCKER_USERNAME -p $DOCKER_PASSWORD + - docker push docker.pbiernat.dev/nginx-php:dev + when: + branch: develop + event: push + volumes: + - name: docker-sock + path: /var/run + +- name: build_feature + image: plugins/docker + commands: + - sleep 5 + - docker build -t docker.pbiernat.dev/nginx-php:$CI_COMMIT_BRANCH . + - docker images --format "{{.Repository}}:{{.Tag}}" | grep nginx-php:${CI_COMMIT_BRANCH} + when: + branch: feature_* + event: push + volumes: + - name: docker-sock + path: /var/run + +- name: publish_feature + image: plugins/docker + privileged: true + environment: + DOCKER_USERNAME: + from_secret: registry_username + DOCKER_PASSWORD: + from_secret: registry_password + commands: + - sleep 5 + - docker login docker.pbiernat.dev -u $DOCKER_USERNAME -p $DOCKER_PASSWORD + - docker push docker.pbiernat.dev/nginx-php:$CI_COMMIT_BRANCH + when: + branch: feature_* + event: push volumes: - name: docker-sock path: /var/run @@ -42,4 +108,3 @@ services: volumes: - name: docker-sock temp: {} - diff --git a/src/etc/nginx/conf.d/default.conf b/src/etc/nginx/conf.d/default.conf index 76e5402..1228c2b 100644 --- a/src/etc/nginx/conf.d/default.conf +++ b/src/etc/nginx/conf.d/default.conf @@ -1,10 +1,8 @@ server { listen 80 default_server; - listen [::]:80 default_server; root /var/www/app/public; location / { - # try to serve file directly, fallback to index.php try_files $uri /index.php$is_args$args; } @@ -14,7 +12,7 @@ server { include fastcgi_params; # optionally set the value of the environment variables used in the application - # fastcgi_param APP_ENV prod; + fastcgi_param APP_ENV dev; # fastcgi_param APP_SECRET ; # fastcgi_param DATABASE_URL "mysql://db_user:db_pass@host:3306/db_name"; @@ -27,7 +25,8 @@ server { # for more information). fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; fastcgi_param DOCUMENT_ROOT $realpath_root; - # Prevents URIs that include the front controller. This will 404: + + # Prevents URIs that include the front controller. This will 404: # http://domain.tld/index.php/some-path # Remove the internal directive to allow URIs like this internal; diff --git a/src/etc/supervisor.d/services.ini b/src/etc/supervisor.d/services.ini index f7e4aaf..8b5e0ec 100644 --- a/src/etc/supervisor.d/services.ini +++ b/src/etc/supervisor.d/services.ini @@ -2,6 +2,7 @@ logfile=/var/log/supervisord.log pidfile=/var/run/supervisord.pid nodaemon=false +user=root [program:nginx] command=/usr/sbin/nginx -g 'daemon off;' @@ -21,4 +22,4 @@ priority=5 stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr -stderr_logfile_maxbytes=0 \ No newline at end of file +stderr_logfile_maxbytes=0 From 9a6b626f971ebbc9b082b3c7196651d98636a613 Mon Sep 17 00:00:00 2001 From: Piotr Biernat Date: Tue, 23 Nov 2021 15:03:51 +0100 Subject: [PATCH 3/9] [fix] Steps --- .drone.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.drone.yml b/.drone.yml index 6588302..c0eaa59 100644 --- a/.drone.yml +++ b/.drone.yml @@ -56,6 +56,7 @@ steps: from_secret: registry_password commands: - sleep 5 + - docker build -t docker.pbiernat.dev/nginx-php:dev . - docker login docker.pbiernat.dev -u $DOCKER_USERNAME -p $DOCKER_PASSWORD - docker push docker.pbiernat.dev/nginx-php:dev when: From 8b2d17f7a2b962f2c388db6e91e70487c14889e7 Mon Sep 17 00:00:00 2001 From: Piotr Biernat Date: Tue, 23 Nov 2021 15:29:27 +0100 Subject: [PATCH 4/9] [fix] Fixed build_develop step --- .drone.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index c0eaa59..9ddb2de 100644 --- a/.drone.yml +++ b/.drone.yml @@ -41,7 +41,9 @@ steps: - docker images --format "{{.Repository}}:{{.Tag}}" | grep nginx-php:dev when: branch: develop - event: pull_request + event: + - pull_request + - push volumes: - name: docker-sock path: /var/run From d8ce78bf0ec70b764b78a10f04c883ef8af9620b Mon Sep 17 00:00:00 2001 From: Piotr Biernat Date: Tue, 23 Nov 2021 15:39:20 +0100 Subject: [PATCH 5/9] [fix] Publish feature tagged image on PR open --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 9ddb2de..09bf139 100644 --- a/.drone.yml +++ b/.drone.yml @@ -95,7 +95,7 @@ steps: - docker push docker.pbiernat.dev/nginx-php:$CI_COMMIT_BRANCH when: branch: feature_* - event: push + event: pull_request volumes: - name: docker-sock path: /var/run From 197cfeba334a514938c500170a7af949190d4b82 Mon Sep 17 00:00:00 2001 From: Piotr Biernat Date: Tue, 23 Nov 2021 15:43:30 +0100 Subject: [PATCH 6/9] [fix] Fix again --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 09bf139..153f75e 100644 --- a/.drone.yml +++ b/.drone.yml @@ -94,7 +94,7 @@ steps: - docker login docker.pbiernat.dev -u $DOCKER_USERNAME -p $DOCKER_PASSWORD - docker push docker.pbiernat.dev/nginx-php:$CI_COMMIT_BRANCH when: - branch: feature_* + branch: develop event: pull_request volumes: - name: docker-sock From 1b7028562c3845c33547cccfe1e8853165c91b27 Mon Sep 17 00:00:00 2001 From: Piotr Biernat Date: Tue, 23 Nov 2021 22:37:43 +0100 Subject: [PATCH 7/9] [fix] Added missing variable --- scripts/drone-build.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/drone-build.sh b/scripts/drone-build.sh index 4236ca8..8e68fc1 100755 --- a/scripts/drone-build.sh +++ b/scripts/drone-build.sh @@ -18,6 +18,7 @@ contains() { branch=$CI_COMMIT_BRANCH event=$CI_BUILD_EVENT source_branch=$DRONE_SOURCE_BRANCH +step_name=$DRONE_STEP_NAME if { contains "$branch" "feature_" && [ "$event" = push ]; } ; then echo "BUILD FEATURE: $branch" From 3f61272b803fe922603940b5d937c3d22f8e1487 Mon Sep 17 00:00:00 2001 From: Piotr Biernat Date: Tue, 23 Nov 2021 22:45:05 +0100 Subject: [PATCH 8/9] [fix] Cleanup --- .drone.yml | 24 +----------------------- scripts/drone-build.sh | 6 +++--- scripts/drone-publish.sh | 2 -- 3 files changed, 4 insertions(+), 28 deletions(-) diff --git a/.drone.yml b/.drone.yml index 8ec2a0f..9796771 100644 --- a/.drone.yml +++ b/.drone.yml @@ -6,10 +6,6 @@ name: Build steps: - name: build_release image: plugins/docker - commands: - - sleep 5 - - docker build -t docker.pbiernat.dev/nginx-php . - - docker images | grep nginx-php when: event: tag volumes: @@ -23,10 +19,6 @@ steps: from_secret: registry_username DOCKER_PASSWORD: from_secret: registry_password - commands: - - sleep 5 -# - docker login docker.pbiernat.dev -u $DOCKER_USERNAME -p $DOCKER_PASSWORD -# - docker push docker.pbiernat.dev/nginx-php when: event: tag volumes: @@ -36,8 +28,6 @@ steps: - name: build_develop image: plugins/docker commands: - - sleep 5 - #- env - ./scripts/drone-build.sh when: branch: develop @@ -49,16 +39,12 @@ steps: - name: publish_develop image: plugins/docker -# privileged: true environment: DOCKER_USERNAME: from_secret: registry_username DOCKER_PASSWORD: from_secret: registry_password commands: - - sleep 5 -# - docker login docker.pbiernat.dev -u $DOCKER_USERNAME -p $DOCKER_PASSWORD -# - docker push docker.pbiernat.dev/nginx-php:dev - ./scripts/drone-publish.sh when: branch: develop @@ -71,10 +57,6 @@ steps: - name: build_feature image: plugins/docker commands: - - env - - sleep 5 - #- docker build -t docker.pbiernat.dev/nginx-php:$CI_COMMIT_BRANCH . - #- docker images --format "{{.Repository}}:{{.Tag}}" | grep nginx-php:${CI_COMMIT_BRANCH} - ./scripts/drone-build.sh when: branch: @@ -89,17 +71,12 @@ steps: - name: publish_feature image: plugins/docker -# privileged: true environment: DOCKER_USERNAME: from_secret: registry_username DOCKER_PASSWORD: from_secret: registry_password commands: -# - env - - sleep 5 - #- docker login docker.pbiernat.dev -u $DOCKER_USERNAME -p $DOCKER_PASSWORD - #- docker push docker.pbiernat.dev/nginx-php:$CI_COMMIT_BRANCH - ./scripts/drone-publish.sh when: branch: develop @@ -120,3 +97,4 @@ services: volumes: - name: docker-sock temp: {} + diff --git a/scripts/drone-build.sh b/scripts/drone-build.sh index 8e68fc1..0cc9e32 100755 --- a/scripts/drone-build.sh +++ b/scripts/drone-build.sh @@ -21,19 +21,19 @@ source_branch=$DRONE_SOURCE_BRANCH step_name=$DRONE_STEP_NAME if { contains "$branch" "feature_" && [ "$event" = push ]; } ; then - echo "BUILD FEATURE: $branch" + sleep 5 docker build -t docker.pbiernat.dev/nginx-php:$branch . return 0 fi if { [ "$branch" = develop ] && [ "$event" = pull_request ]; } ; then - echo "BUILD FEATURE(FROM DEV): $source_branch" + sleep 5 docker build -t docker.pbiernat.dev/nginx-php:$source_branch . return 0 fi if { [ "$branch" = develop ] && [ "$event" = push ] && [ "$step_name" != build_feature ]; } ; then - echo "BUILD DEV" + sleep 5 docker build -t docker.pbiernat.dev/nginx-php:dev . return 0 fi diff --git a/scripts/drone-publish.sh b/scripts/drone-publish.sh index 572645d..12d098e 100755 --- a/scripts/drone-publish.sh +++ b/scripts/drone-publish.sh @@ -20,13 +20,11 @@ source_branch=$DRONE_SOURCE_BRANCH docker login docker.pbiernat.dev -u $DOCKER_USERNAME -p $DOCKER_PASSWORD if { [ "$branch" = develop ] && [ "$event" = pull_request ]; } ; then - echo "PUSH FEATURE: $source_branch" docker push docker.pbiernat.dev/nginx-php:$source_branch return 0 fi if { [ "$branch" = develop ] && [ "$event" = push ]; } ; then - echo "PUSH DEV: $branch" docker push docker.pbiernat.dev/nginx-php:dev return 0 fi From f8f8388665b06815b1f3c1ebaa7548d750f426f6 Mon Sep 17 00:00:00 2001 From: Piotr Biernat Date: Tue, 23 Nov 2021 23:13:36 +0100 Subject: [PATCH 9/9] [fix] Cleanup drone scripts --- scripts/drone-build.sh | 4 ---- scripts/drone-publish.sh | 2 -- 2 files changed, 6 deletions(-) diff --git a/scripts/drone-build.sh b/scripts/drone-build.sh index 0cc9e32..24ab330 100755 --- a/scripts/drone-build.sh +++ b/scripts/drone-build.sh @@ -1,9 +1,5 @@ #!/bin/sh -# - docker build -t docker.pbiernat.dev/nginx-php:$CI_COMMIT_BRANCH . -# - docker images --format "{{.Repository}}:{{.Tag}}" | grep nginx-php:${CI_COMMIT_BRANCH} - - contains() { string="$1" substring="$2" diff --git a/scripts/drone-publish.sh b/scripts/drone-publish.sh index 12d098e..ca242ba 100755 --- a/scripts/drone-publish.sh +++ b/scripts/drone-publish.sh @@ -1,7 +1,5 @@ #!/bin/sh -# docker push docker.pbiernat.dev/nginx-php:$CI_COMMIT_BRANCH - contains() { string="$1" substring="$2"