Skip to content

Instantly share code, notes, and snippets.

@hyperized
Last active December 24, 2019 10:18

Revisions

  1. hyperized revised this gist Dec 24, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion .gitlab-ci.yml
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@ stages:

    variables:
    MYPATH: "/home/site/"
    MYSSH: "ssh -p 50 -t $SSH_USER@$SSH_IP"
    MYSSH: "ssh -t $SSH_USER@$SSH_IP"

    .ssh: &ssh
    image: hyperized/openssh-client
  2. hyperized revised this gist Dec 24, 2019. 1 changed file with 24 additions and 3 deletions.
    27 changes: 24 additions & 3 deletions .gitlab-ci.yml
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,16 @@
    ---
    stages:
    - pull
    - npm
    - push
    - permissions
    - composer
    - migrations
    - optimize

    variables:
    MYPATH: "/path/to/public"
    MYSSH: "ssh -t $SSH_USER@$SSH_IP"
    MYPATH: "/home/site/"
    MYSSH: "ssh -p 50 -t $SSH_USER@$SSH_IP"

    .ssh: &ssh
    image: hyperized/openssh-client
    @@ -35,11 +37,30 @@ pull_on_server:
    - $MYSSH "cd $MYPATH && git reset --hard"
    - $MYSSH "cd $MYPATH && git pull $CI_REPOSITORY_URL"

    npm:
    stage: npm
    image: node
    script:
    - npm install
    - npm run production
    artifacts:
    paths:
    - public/css
    - public/js
    expire_in: 1 hour

    push_to_server:
    stage: push
    <<: *ssh
    script:
    - scp -P 50 -rv public/css $SSH_USER@$SSH_IP:$MYPATH/public/
    - scp -P 50 -rv public/js $SSH_USER@$SSH_IP:$MYPATH/public/

    permissions:
    stage: permissions
    <<: *ssh
    script:
    - $MYSSH "sudo chown -R user:www-data $MYPATH"
    - $MYSSH "sudo chown -R site:www-data $MYPATH"
    - $MYSSH "sudo find $MYPATH -type f -exec chmod 664 {} \;"
    - $MYSSH "sudo find $MYPATH -type d -exec chmod 775 {} \;"
    - $MYSSH "sudo chgrp -R www-data $MYPATH/storage $MYPATH/bootstrap/cache"
  3. hyperized created this gist Dec 24, 2019.
    73 changes: 73 additions & 0 deletions .gitlab-ci.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,73 @@
    ---
    stages:
    - pull
    - permissions
    - composer
    - migrations
    - optimize

    variables:
    MYPATH: "/path/to/public"
    MYSSH: "ssh -t $SSH_USER@$SSH_IP"

    .ssh: &ssh
    image: hyperized/openssh-client
    before_script:
    - eval $(ssh-agent -s)
    - ssh-add <(echo "$SSH_PRIVATE_KEY")
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
    - echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
    - echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
    - chmod 644 ~/.ssh/known_hosts
    only:
    refs:
    - master

    .tags: &tags
    tags:
    - gcp

    pull_on_server:
    stage: pull
    <<: *ssh
    script:
    - $MYSSH "cd $MYPATH && git reset --hard"
    - $MYSSH "cd $MYPATH && git pull $CI_REPOSITORY_URL"

    permissions:
    stage: permissions
    <<: *ssh
    script:
    - $MYSSH "sudo chown -R user:www-data $MYPATH"
    - $MYSSH "sudo find $MYPATH -type f -exec chmod 664 {} \;"
    - $MYSSH "sudo find $MYPATH -type d -exec chmod 775 {} \;"
    - $MYSSH "sudo chgrp -R www-data $MYPATH/storage $MYPATH/bootstrap/cache"
    - $MYSSH "sudo chmod -R ug+rwx $MYPATH/storage $MYPATH/bootstrap/cache"
    <<: *tags

    migrations:
    stage: migrations
    <<: *ssh
    script:
    - $MYSSH "cd $MYPATH && php artisan migrate"
    - $MYSSH "redis-cli FLUSHALL"
    <<: *tags

    composer:
    stage: composer
    <<: *ssh
    script:
    - $MYSSH "cd $MYPATH && composer install --no-progress --no-suggest --optimize-autoloader --no-dev --ignore-platform-reqs"
    <<: *tags

    optimize:
    stage: optimize
    <<: *ssh
    script:
    - $MYSSH "cd $MYPATH && php artisan nova:publish --force"
    - $MYSSH "cd $MYPATH && php artisan view:cache"
    - $MYSSH "cd $MYPATH && php artisan config:cache"
    - $MYSSH "cd $MYPATH && php artisan event:cache"
    - $MYSSH "cd $MYPATH && php artisan route:cache"
    <<: *tags