Skip to content

Instantly share code, notes, and snippets.

@Pierozi
Created April 10, 2019 06:28
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 Pierozi/0c8f251f4186d19d88acaa8047082a9f to your computer and use it in GitHub Desktop.
Save Pierozi/0c8f251f4186d19d88acaa8047082a9f to your computer and use it in GitHub Desktop.
Gitlab CI Wortimmo
stages:
- package
- test
- deploy
package:test:
stage: package
image: wortimmo/php:7.2-xdebug
before_script:
# install ssh-agent
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
# run ssh-agent
- eval $(ssh-agent -s)
# add ssh key stored in SSH_PRIVATE_KEY variable to the agent store
- ssh-add <(echo "$SSH_PRIVATE_KEY")
# disable host key checking (NOTE: makes you susceptible to man-in-the-middle attacks)
# WARNING: use only in docker container, if you use it with shell you will overwrite your user's ssh config
- mkdir -p ~/.ssh
- echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
script:
- composer install --no-interaction --no-scripts --no-progress
- yarn install
- yarn run dev
- node_modules/.bin/webpack --config assets/js/search/webpack.config.js
artifacts:
name: "prepare-wortimmo-portail-$CI_JOB_NAME-$CI_COMMIT_REF_NAME"
expire_in: 1 week
paths:
- .
package:dist:
stage: package
image: wortimmo/php:7.2-xdebug
before_script:
# install ssh-agent
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
# run ssh-agent
- eval $(ssh-agent -s)
# add ssh key stored in SSH_PRIVATE_KEY variable to the agent store
- ssh-add <(echo "$SSH_PRIVATE_KEY")
# disable host key checking (NOTE: makes you susceptible to man-in-the-middle attacks)
# WARNING: use only in docker container, if you use it with shell you will overwrite your user's ssh config
- mkdir -p ~/.ssh
- echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
only:
- feat/code-deploy
- master
- tags
script:
- echo -e "Commit:$CI_COMMIT_SHA\nJob:$CI_JOB_ID\nRef:$CI_COMMIT_REF_NAME\nBy:$GITLAB_USER_NAME\ndate:$(date --rfc-3339=seconds)" > public/ci-package.txt
- composer install --no-interaction --no-scripts --no-dev --no-progress
- yarn install
- yarn run build
- node_modules/.bin/webpack --config assets/js/search/webpack.config.js
- rm -rf .git
artifacts:
name: "dist-wortimmo-portail-$CI_JOB_NAME-$CI_COMMIT_REF_NAME"
paths:
- .
test:phpcs:
image: wortimmo/php:7.2-xdebug
stage: test
dependencies:
- package:test
variables:
GIT_STRATEGY: none
script:
- ./vendor/bin/phpcs --standard=phpcs.xml ./src
test:phpunit:
image: wortimmo/php:7.2-xdebug
stage: test
dependencies:
- package:test
variables:
GIT_STRATEGY: none
script:
- php bin/phpunit
test:yarncs:
image: wortimmo/php:7.2-xdebug
stage: test
dependencies:
- package:test
variables:
GIT_STRATEGY: none
script:
- yarn cs
deployment:
image: xueshanf/awscli:latest
stage: deploy
dependencies:
- package:dist
only:
- feat/code-deploy
- master
- tags
when: on_success
variables:
GIT_STRATEGY: none
script:
- export CI_COMMIT_REF_NAME=`echo $CI_COMMIT_REF_NAME | sed 's/[^a-z0-9-]/_/gi'`
- if [ -z "$CI_COMMIT_TAG" ]; then export BUNDLE_ENV=staging; fi
- if [ -z "$BUNDLE_ENV" ]; then export BUNDLE_ENV=production; fi
- echo "Upload artifact to S3"
- export PACKAGE_NAME=portail-$BUNDLE_ENV-$CI_COMMIT_REF_NAME-$CI_BUILD_ID.tar.gz
- tar czf /tmp/$PACKAGE_NAME ./
- aws s3 cp /tmp/$PACKAGE_NAME s3://wortimmo-repository/codedeploy/portail/$BUNDLE_ENV/$PACKAGE_NAME
- aws deploy create-deployment --application-name Portail --s3-location bucket=wortimmo-repository,key=codedeploy/portail/$BUNDLE_ENV/$PACKAGE_NAME,bundleType=tgz --deployment-group-name $BUNDLE_ENV --description "Deployment $BUNDLE_ENV related to $CI_COMMIT_REF_NAME"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment