File: /var/www/quadcode/.gitlab-ci.yml
stages:
- build
- deploy
- geoip
build:backend:
stage: build
image: composer:latest
before_script:
- PWD_DIR=$(pwd)
script:
- cd $PWD_DIR
- sed -E "s/\{\{\s*lookup\('env', '([^']+)'\)\s*\}\}/\$\1/g" .deploy/playbooks/files/.env_main > ./tmp_vars
- |
while IFS= read -r line; do
eval "echo \"$line\""
done < ./tmp_vars > ./.env
- composer install --ignore-platform-req=php --ignore-platform-req=ext-intl --ignore-platform-req=ext-gd --ignore-platform-req=ext-gmp
artifacts:
name: quadcode_backend
expire_in: 1d
paths:
- vendor
tags: [linux_amd64_standard, production]
build:frontend_backend:
stage: build
image: node:lts-alpine3.14
before_script:
- PWD_DIR=$(pwd)
script:
- cd $PWD_DIR
- sed -E "s/\{\{\s*lookup\('env', '([^']+)'\)\s*\}\}/\$\1/g" .deploy/playbooks/files/.env_main > ./tmp_vars
- |
while IFS= read -r line; do
eval "echo \"$line\""
done < ./tmp_vars > ./.env
- npx yarn install
- npx yarn build
cache: []
artifacts:
name: quadcode_front_backend
expire_in: 1d
paths:
- public
tags: [linux_amd64_standard, production]
only:
- deploy
build:frontend:
stage: build
image: node:lts-alpine3.14
before_script:
- PWD_DIR=$(pwd)
script:
- cd $PWD_DIR
- sed -E "s/\{\{\s*lookup\('env', '([^']+)'\)\s*\}\}/\$\1/g" .deploy/playbooks/files/.env_main > ./tmp_vars
- |
while IFS= read -r line; do
eval "echo \"$line\""
done < ./tmp_vars > ./.env
- cd $PWD_DIR/frontend
- cp ../.env .env
- node -v
- npx yarn install
- npx yarn build
cache: []
artifacts:
name: quadcode_frontend
expire_in: 1d
paths:
- frontend/dist
tags: [linux_amd64_standard, production]
only:
- deploy
build:one-time-popup:
stage: build
image: node:22-alpine
before_script:
- PWD_DIR=$(pwd)
script:
- cd $PWD_DIR
- sed -E "s/\{\{\s*lookup\('env', '([^']+)'\)\s*\}\}/\$\1/g" .deploy/playbooks/files/.env_main | grep VITE > ./tmp_vars
- |
while IFS= read -r line; do
eval "echo \"$line\""
done < ./tmp_vars > ./.env
- cd $PWD_DIR/one-time-popup
- cp ../.env .env
- node -v
- npx yarn install
- npx yarn build
cache: []
artifacts:
name: quadcode_one_time_popup
expire_in: 1d
paths:
- one-time-popup/build
tags: [linux_amd64_standard, production]
only:
- deploy
deploy:production:
stage: deploy
before_script:
- export GITLAB_DEPLOY_TO=production
- PWD_DIR=$(pwd)
script:
- test "${SSH_KEY}" || exit 1
- mkdir -m 700 ~/.ssh
- echo "${SSH_KEY}" > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- eval `ssh-agent -s`
- ssh-add ~/.ssh/id_rsa
- ssh-keyscan gitlab.mobbtech.com >> ~/.ssh/known_hosts
- ls frontend/
- |
tar -czf $PWD_DIR/.deploy/playbooks/app.tgz app artisan bootstrap composer.json composer.lock config database \
frontend/dist package-lock.json package.json phpunit.xml public resources routes server.php storage frontend/webpack.mix.js \
vendor one-time-popup/build one-time-popup/public
- chmod -v 700 $PWD_DIR/.deploy
- cd $PWD_DIR/.deploy && ansible-galaxy install -r roles/requirements.yml
- chmod 755 $PWD_DIR/.deploy && cd $PWD_DIR/.deploy && ansible-playbook -i inventory -l quadcode_aws playbooks/.deploy.yml -vv -D
image: registry.mobbtech.com/infra/ansible-ci:2.9.14-2
environment: production
dependencies:
- build:frontend
- build:backend
- build:frontend_backend
- build:one-time-popup
tags:
- production
# only:
# - deploy
# - 520907
when: manual
.geoip-update: &geoip-update
stage: geoip
image: registry.mobbtech.com/infra/ansible-ci:2.9.14-5
before_script:
- mkdir -m 700 ~/.ssh
- echo "$SSH_KEY" > ~/.ssh/id_rsa
- ssh-keyscan gitlab.mobbtech.com >> ~/.ssh/known_hosts
- chmod 600 ~/.ssh/id_rsa
- mkdir -p -m 700 ~/.ansible/roles
- PWD_DIR=$(pwd)
- cd $PWD_DIR/.deploy && export ANSIBLE_CONFIG=ansible.cfg && ansible-galaxy install -r roles/requirements.yml -vv
- sed -i 's/mozilla\/DST_Root_CA_X3/!mozilla\/DST_Root_CA_X3/g' /etc/ca-certificates.conf && update-ca-certificates
- apt-get update; apt-get install s3cmd -y
script:
- s3cmd --access_key="${S3_ACCESS_KEY}" --secret_key="${S3_SECRET_KEY}" --host=s3-infra-wz-ams.lo.mobbtech.com --host-bucket=s3-infra-wz-ams.lo.mobbtech.com get s3://geoip-db-antifraud/GeoIP2-City.mmdb /tmp
tags:
- linux_amd64_standard
geoip-update-prod:
<<: *geoip-update
script:
- s3cmd --access_key="${S3_ACCESS_KEY}" --secret_key="${S3_SECRET_KEY}" --host=s3-infra-wz-ams.lo.mobbtech.com --host-bucket=s3-infra-wz-ams.lo.mobbtech.com get s3://geoip-db-antifraud/GeoIP2-City.mmdb /tmp
- chmod 755 $PWD_DIR/.deploy && cd $PWD_DIR/.deploy && ansible-playbook -i inventory -l quadcode_aws playbooks/.deploy.yml -vv -D -t geoip
rules:
- if: '$CI_PIPELINE_SOURCE == "schedule"'
when: on_success
- if: '$CI_COMMIT_REF_NAME == "deploy"'
when: manual