Created
August 29, 2020 16:41
-
-
Save spicydog/84955b707c3e1da14800e15c52c73949 to your computer and use it in GitHub Desktop.
SPICYDOG's Podcast EP 4 : Sample Scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# exit with error | |
set -e | |
# Generate an application key. Re-cache. | |
php artisan config:cache | |
php artisan config:clear | |
php artisan cache:clear | |
# Run database migrations and seeds. | |
php artisan migrate --seed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
before_script: | |
- "[[ ! -e /.dockerenv ]] && exit 0" | |
stages: | |
- dependency | |
- build | |
- test | |
- release | |
- deploy | |
- coverage | |
variables: | |
# MySQL configuration | |
MYSQL_ROOT_PASSWORD: root | |
MYSQL_DATABASE: homestead | |
MYSQL_USER: homestead | |
MYSQL_PASSWORD: secret | |
DB_HOST: dbtest | |
# dind configuration | |
DOCKER_HOST: tcp://docker:2375/ | |
DOCKER_DRIVER: overlay2 | |
dependency:yarn: | |
stage: dependency | |
image: node:12.18-buster-slim | |
cache: | |
untracked: true | |
key: "$CI_COMMIT_REF_SLUG-node_modules" | |
paths: | |
- node_modules/ | |
script: | |
- yarn install --frozen-lockfile | |
artifacts: | |
paths: | |
- node_modules/ | |
expire_in: 1 days | |
when: always | |
retry: 1 | |
dependency:composer: | |
stage: dependency | |
image: composer | |
cache: | |
untracked: true | |
key: "$CI_COMMIT_REF_SLUG-vendor" | |
paths: | |
- vendor/ | |
script: | |
- composer install --prefer-dist --no-ansi --no-interaction --no-progress | |
artifacts: | |
paths: | |
- ./vendor | |
expire_in: 1 days | |
when: always | |
build:yarn:customer: | |
stage: build | |
image: node:12.18-buster-slim | |
dependencies: | |
- dependency:yarn | |
needs: | |
- dependency:yarn | |
script: | |
- yarn run prod-customer | |
artifacts: | |
paths: | |
- ./public/dist/customers | |
expire_in: 1 days | |
retry: 1 | |
build:yarn:institution: | |
stage: build | |
image: node:12.18-buster-slim | |
dependencies: | |
- dependency:yarn | |
needs: | |
- dependency:yarn | |
script: | |
- yarn run prod-institution | |
artifacts: | |
paths: | |
- ./public/dist/institutions | |
expire_in: 1 days | |
retry: 1 | |
build:yarn:asset: | |
stage: build | |
image: node:12.18-buster-slim | |
dependencies: | |
- dependency:yarn | |
needs: | |
- dependency:yarn | |
script: | |
- yarn run prod-assets | |
artifacts: | |
paths: | |
- ./public/dist/assets | |
expire_in: 1 days | |
retry: 1 | |
test:phpunit: | |
stage: test | |
image: registry.gitlab.com/creditok/docker-nginx-php-laravel/master:fc9352c7accb1153132a4ad3f2c3edbe2efe1bfa | |
services: | |
- name: mysql:5.7 | |
alias: dbtest | |
dependencies: | |
- dependency:composer | |
needs: | |
- dependency:composer | |
script: | |
- cat .env.test > .env | |
- echo "$TESTING_GOOGLE_SERVICE_ACCOUNT_JSON" > "$CI_PROJECT_DIR/json/credit-ok-testing.json" | |
- sh .gitlab-ci.sh | |
- php composer.phar dump-autoload | |
- php vendor/bin/paratest -p8 | |
artifacts: | |
paths: | |
- ./storage/logs # for debugging | |
expire_in: 1 days | |
when: always | |
test:migration: | |
stage: test | |
image: registry.gitlab.com/creditok/docker-nginx-php-laravel/master:fc9352c7accb1153132a4ad3f2c3edbe2efe1bfa | |
services: | |
- name: mysql:5.7 | |
alias: dbtest | |
dependencies: | |
- dependency:composer | |
needs: | |
- dependency:composer | |
script: | |
- cat .env.test > .env | |
- sed -i 's/testing/production/g' .env | |
- cat .env | |
- echo "$TESTING_GOOGLE_SERVICE_ACCOUNT_JSON" > "$CI_PROJECT_DIR/json/credit-ok-testing.json" | |
- sh .gitlab-ci.sh | |
- php artisan migrate:rollback # run refresh to make sure migration working properly | |
artifacts: | |
paths: | |
- ./storage/logs # for debugging | |
expire_in: 1 days | |
when: always | |
test:yarn: | |
stage: test | |
image: node:12.18-buster-slim | |
dependencies: | |
- dependency:yarn | |
needs: | |
- dependency:yarn | |
script: | |
- yarn test | |
retry: 1 | |
release:docker: | |
stage: release | |
image: docker:stable | |
services: | |
- docker:dind | |
dependencies: | |
- dependency:composer | |
- build:yarn:asset | |
- build:yarn:institution | |
- build:yarn:customer | |
script: | |
- docker info | |
- rm -rf ./resources/js/ | |
- rm -f .env | |
- docker build --pull -t app_image . | |
# Login to GCP | |
- echo $GCP_SERVICE_ACCOUNT > ~/service-account.json | |
- docker login -u _json_key --password-stdin https://asia.gcr.io < ~/service-account.json | |
# Tag and push to GCR (build ref & latest) | |
- docker tag app_image asia.gcr.io/$CLOUDSDK_CORE_PROJECT/$CI_PROJECT_NAME/$CI_COMMIT_REF_NAME:$CI_BUILD_REF | |
- docker push asia.gcr.io/$CLOUDSDK_CORE_PROJECT/$CI_PROJECT_NAME/$CI_COMMIT_REF_NAME:$CI_BUILD_REF | |
- docker tag app_image asia.gcr.io/$CLOUDSDK_CORE_PROJECT/$CI_PROJECT_NAME/$CI_COMMIT_REF_NAME:latest | |
- docker push asia.gcr.io/$CLOUDSDK_CORE_PROJECT/$CI_PROJECT_NAME/$CI_COMMIT_REF_NAME:latest | |
only: | |
- master | |
- develop | |
tags: | |
- docker | |
retry: 1 | |
# Depends on CLOUDSDK_CORE_PROJECT, CLOUDSDK_CONTAINER_CLUSTER, and CLOUDSDK_COMPUTE_ZONE being set | |
deploy:kubectl:uat: | |
stage: deploy | |
image: registry.gitlab.com/creditok/google-cloud-sdk-kubectl/master:latest | |
dependencies: | |
- release:docker | |
script: | |
- echo $GCP_SERVICE_ACCOUNT > ~/service-account.json | |
- gcloud auth activate-service-account --key-file ~/service-account.json | |
- gcloud --quiet container clusters get-credentials $CLOUDSDK_CONTAINER_CLUSTER | |
- kubectl cluster-info | |
- kubectl --namespace app patch deployment app-dev-app -p '{"spec":{"template":{"spec":{"containers":[{"name":"app","imagePullPolicy":"IfNotPresent","image":"'"asia.gcr.io/$CLOUDSDK_CORE_PROJECT/$CI_PROJECT_NAME/$CI_COMMIT_REF_NAME:$CI_BUILD_REF"'"}]}}}}' | |
- kubectl --namespace app patch deployment app-dev-queue -p '{"spec":{"template":{"spec":{"containers":[{"name":"app","imagePullPolicy":"IfNotPresent","image":"'"asia.gcr.io/$CLOUDSDK_CORE_PROJECT/$CI_PROJECT_NAME/$CI_COMMIT_REF_NAME:$CI_BUILD_REF"'"}]}}}}' | |
- kubectl --namespace app patch deployment app-dev-scheduler -p '{"spec":{"template":{"spec":{"containers":[{"name":"app","imagePullPolicy":"IfNotPresent","image":"'"asia.gcr.io/$CLOUDSDK_CORE_PROJECT/$CI_PROJECT_NAME/$CI_COMMIT_REF_NAME:$CI_BUILD_REF"'"}]}}}}' | |
only: | |
- develop | |
deploy:kubectl:production: | |
stage: deploy | |
image: registry.gitlab.com/creditok/google-cloud-sdk-kubectl/master:latest | |
dependencies: | |
- release:docker | |
script: | |
- echo $GCP_SERVICE_ACCOUNT > ~/service-account.json | |
- gcloud auth activate-service-account --key-file ~/service-account.json | |
- gcloud --quiet container clusters get-credentials $CLOUDSDK_CONTAINER_CLUSTER | |
- kubectl cluster-info | |
- kubectl --namespace app patch deployment app-prod-app -p '{"spec":{"template":{"spec":{"containers":[{"name":"app","imagePullPolicy":"IfNotPresent","image":"'"asia.gcr.io/$CLOUDSDK_CORE_PROJECT/$CI_PROJECT_NAME/$CI_COMMIT_REF_NAME:$CI_BUILD_REF"'"}]}}}}' | |
- kubectl --namespace app patch deployment app-prod-queue -p '{"spec":{"template":{"spec":{"containers":[{"name":"app","imagePullPolicy":"IfNotPresent","image":"'"asia.gcr.io/$CLOUDSDK_CORE_PROJECT/$CI_PROJECT_NAME/$CI_COMMIT_REF_NAME:$CI_BUILD_REF"'"}]}}}}' | |
- kubectl --namespace app patch deployment app-prod-scheduler -p '{"spec":{"template":{"spec":{"containers":[{"name":"app","imagePullPolicy":"IfNotPresent","image":"'"asia.gcr.io/$CLOUDSDK_CORE_PROJECT/$CI_PROJECT_NAME/$CI_COMMIT_REF_NAME:$CI_BUILD_REF"'"}]}}}}' | |
only: | |
- master | |
coverage:php7.2:mysql5.7: | |
stage: coverage | |
image: edbizarro/gitlab-ci-pipeline-php:7.2 | |
services: | |
- name: mysql:5.7 | |
alias: dbtest | |
dependencies: | |
- dependency:composer | |
needs: | |
- dependency:composer | |
script: | |
- cat .env.test > .env | |
- echo "$TESTING_GOOGLE_SERVICE_ACCOUNT_JSON" > "$CI_PROJECT_DIR/json/credit-ok-testing.json" | |
- sudo chown -R php:php ./storage/ | |
- sh .gitlab-ci.sh | |
- php vendor/bin/paratest -p8 --coverage-html coverage --coverage-text | |
artifacts: | |
paths: | |
- ./storage/logs # for debugging | |
- ./coverage # for debugging | |
expire_in: 7 days | |
when: always | |
allow_failure: true | |
only: | |
- master | |
- develop |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: "3.5" | |
services: | |
# Application (App) | |
app: | |
image: registry.gitlab.com/creditok/docker-nginx-php-laravel/master:fc9352c7accb1153132a4ad3f2c3edbe2efe1bfa | |
depends_on: | |
- database | |
working_dir: /var/www/html/ | |
volumes: | |
- ./:/var/www/html:cached | |
env_file: | |
- "docker-compose.env" | |
environment: | |
- "CONTAINER_ROLE=app" | |
ports: | |
- "8080:8080" | |
networks: | |
- app | |
# Application (Queue) | |
queue: | |
image: registry.gitlab.com/creditok/docker-nginx-php-laravel/master:fc9352c7accb1153132a4ad3f2c3edbe2efe1bfa | |
working_dir: /var/www/html/ | |
depends_on: | |
- database | |
volumes: | |
- ./:/var/www/html:cached | |
env_file: | |
- "docker-compose.env" | |
environment: | |
- "CONTAINER_ROLE=queue" | |
networks: | |
- app | |
# Application (Scheduler) | |
scheduler: | |
image: registry.gitlab.com/creditok/docker-nginx-php-laravel/master:fc9352c7accb1153132a4ad3f2c3edbe2efe1bfa | |
working_dir: /var/www/html/ | |
depends_on: | |
- database | |
volumes: | |
- ./:/var/www/html:cached | |
env_file: | |
- "docker-compose.env" | |
environment: | |
- "CONTAINER_ROLE=scheduler" | |
networks: | |
- app | |
# Database (MySQL) | |
database: | |
image: mysql:5.6 | |
volumes: | |
- dbdata:/var/lib/mysql | |
environment: | |
- "MYSQL_DATABASE=homestead" | |
- "MYSQL_USER=homestead" | |
- "MYSQL_PASSWORD=secret" | |
- "MYSQL_ROOT_PASSWORD=secret" | |
ports: | |
- "33061:3306" | |
networks: | |
- app | |
dbtest: | |
image: mysql:5.6 | |
volumes: | |
- dbtest:/var/lib/mysql | |
environment: | |
- "MYSQL_DATABASE=homestead" | |
- "MYSQL_USER=homestead" | |
- "MYSQL_PASSWORD=secret" | |
- "MYSQL_ROOT_PASSWORD=secret" | |
ports: | |
- "33063:3306" | |
networks: | |
- app | |
volumes: | |
dbdata: | |
dbtest: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM registry.gitlab.com/creditok/docker-nginx-php-laravel/master:fc9352c7accb1153132a4ad3f2c3edbe2efe1bfa | |
COPY ./ /var/www/html/ | |
RUN chown -R www-data /var/www/html/storage/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://gitlab.com/creditok/docker-nginx-php-laravel |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment