{"action":"closed","issue":{"url":"https://api.github.com/repos/lorisleiva/laravel-deployer/issues/31","repository_url":"https://api.github.com/repos/lorisleiva/laravel-deployer","labels_url":"https://api.github.com/repos/lorisleiva/laravel-deployer/issues/31/labels{/name}","comments_url":"https://api.github.com/repos/lorisleiva/laravel-deployer/issues/31/comments","events_url":"https://api.github.com/repos/lorisleiva/laravel-deployer/issues/31/events","html_url":"https://github.com/lorisleiva/laravel-deployer/issues/31","id":341325533,"node_id":"MDU6SXNzdWUzNDEzMjU1MzM=","number":31,"title":"Access denied when run artisan:migrate using deployer","user":{"login":"satyakresna","id":11099186,"node_id":"MDQ6VXNlcjExMDk5MTg2","avatar_url":"https://avatars2.githubusercontent.com/u/11099186?v=4","gravatar_id":"","url":"https://api.github.com/users/satyakresna","html_url":"https://github.com/satyakresna","followers_url":"https://api.github.com/users/satyakresna/followers","following_url":"https://api.github.com/users/satyakresna/following{/other_user}","gists_url":"https://api.github.com/users/satyakresna/gists{/gist_id}","starred_url":"https://api.github.com/users/satyakresna/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/satyakresna/subscriptions","organizations_url":"https://api.github.com/users/satyakresna/orgs","repos_url":"https://api.github.com/users/satyakresna/repos","events_url":"https://api.github.com/users/satyakresna/events{/privacy}","received_events_url":"https://api.github.com/users/satyakresna/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-07-15T14:33:02Z","updated_at":"2018-07-26T09:34:06Z","closed_at":"2018-07-26T09:34:06Z","author_association":"NONE","body":"Hi @lorisleiva , I just try to use another strategy when deploy project using laravel deployer. In my project, database production and staging is different. So, I would like to update the value automatically using Gitlab CI/CD Variables. I create 4 stage: init, **build, test and deploy**. \r\n\r\nIn **init** section I login to ssh and update value of env for production and staging. Also in **init** stage I create artifact to download the env production and staging. In deploy section, I just run the script to update value .env with env staging like this: `cp .env.staging .env`. In section script `artisan:migrate`, **it denied access my user database**. But, I'm already try to test value the database in env in my server with ssh terminal.\r\n\r\nI'm curious why it can be happened?\r\n\r\nHere's my **gitlab-ci.yml**\r\n\r\n**gitlab-ci.yml**\r\n\r\n```\r\n# Add a `.` in front of a job to make it hidden.\r\n# Add a `&reference` to make it a reusable template.\r\n# Note that we don't have dashes anymore.\r\n.init_ssh: &init_ssh |\r\n  eval $(ssh-agent -s)\r\n  echo \"$SSH_PRIVATE_KEY\" | tr -d '\\r' | ssh-add - > /dev/null\r\n  mkdir -p ~/.ssh\r\n  chmod 700 ~/.ssh\r\n  [[ -f /.dockerenv ]] && echo -e \"Host *\\n\\tStrictHostKeyChecking no\\n\\n\" > ~/.ssh/config\r\n\r\n  # Replace the last line with the following lines if you'd rather\r\n# leave StrictHostKeyChecking enabled (replace yourdomain.com):\r\n#\r\n#  ssh-keyscan yourdomain.com >> ~/.ssh/known_hosts\r\n#  chmod 644 ~/.ssh/known_hosts\r\n\r\n.change_file_permissions: &change_file_permissions |\r\n  find . -type f -not -path \"./vendor/*\" -exec chmod 664 {} \\;\r\n  find . -type d -not -path \"./vendor/*\" -exec chmod 775 {} \\;\r\n\r\nstages:\r\n    - init\r\n    - build\r\n    - test\r\n    - deploy\r\n\r\nsetup_conf_staging:\r\n    stage: init\r\n    image: ubuntu:18.04\r\n    script:\r\n        - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'\r\n        - eval $(ssh-agent -s)\r\n        - ssh-add <(echo \"$SSH_PRIVATE_KEY\")\r\n        - mkdir -p ~/.ssh\r\n        - ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP \" cd $DIR_ENV_STAGING && echo $ENV_STAGING > .env && cp .env .env.staging \"\r\n        - scp -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP:$DIR_ENV_STAGING/.env.staging $PWD\r\n    artifacts:\r\n        paths:\r\n            - .env.staging\r\n\r\nsetup_conf_production:\r\n    stage: init\r\n    image: ubuntu:18.04\r\n    script:\r\n        - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'\r\n        - eval $(ssh-agent -s)\r\n        - ssh-add <(echo \"$SSH_PRIVATE_KEY\")\r\n        - mkdir -p ~/.ssh\r\n        - ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP \" cd $DIR_ENV_PRODUCTION && echo $ENV_PRODUCTION > .env && cp .env .env.production \"\r\n        - scp -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP:$DIR_ENV_PRODUCTION/.env.production $PWD\r\n    artifacts:\r\n        paths:\r\n            - .env.production\r\n\r\ncomposer:\r\n    # The job's stage (build, test or deploy).\r\n    stage: build\r\n    image: lorisleiva/laravel-docker:latest\r\n    # What to run on the job.\r\n    script:\r\n        - composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts\r\n        - cp .env.example .env\r\n        - php artisan key:generate\r\n\r\n    artifacts:\r\n\r\n        # (Optional) Give it an expiration date,\r\n        # after that period you won't be able to\r\n        # download them via the UI anymore.\r\n        expire_in: 1 month\r\n\r\n        # Define what to ouput from the job.\r\n        paths:\r\n            - vendor/\r\n            - .env\r\n\r\n    cache:\r\n\r\n        # The variable CI_COMMIT_REF_SLUG\r\n        # refers to the slug of the branch.\r\n        # For example: `master` for the master branch.\r\n        # We use the `composer` suffix to avoid conflicts with\r\n        # the `npm` cache that we'll define next.\r\n        key: ${CI_COMMIT_REF_SLUG}-composer\r\n\r\n        # Define what to cache.\r\n        paths:\r\n            - vendor/\r\n\r\nnpm:\r\n    # The job's stage (build, test or deploy).\r\n    stage: build\r\n    image: lorisleiva/laravel-docker:latest\r\n    # What to run on the job.\r\n    script:\r\n        - npm install\r\n        - npm run production\r\n\r\n    artifacts:\r\n\r\n        # (Optional) Give it an expiration date,\r\n        # after that period you won't be able to\r\n        # download them via the UI anymore.\r\n        expire_in: 1 month\r\n\r\n        # Define what to ouput from the job.\r\n        paths:\r\n            - node_modules/\r\n            - public/js\r\n            - public/css\r\n\r\n    cache:\r\n\r\n        key: ${CI_COMMIT_REF_SLUG}-composer\r\n\r\n        # Define what to cache.\r\n        paths:\r\n            - node_modules/\r\n\r\nphpunit:\r\n    stage: test\r\n    image: lorisleiva/laravel-docker:latest\r\n    # List of jobs from which it will download the artifacts.\r\n    dependencies:\r\n        - composer\r\n\r\n    script:\r\n        - phpunit --coverage-text --colors=never\r\n\r\ncodestyle:\r\n    stage: test\r\n    image: lorisleiva/laravel-docker:latest\r\n    dependencies: []\r\n    script:\r\n        - phpcs --standard=PSR2 --extensions=php app\r\n\r\n\r\nstaging:\r\n    stage: deploy\r\n    image: lorisleiva/laravel-docker:latest\r\n    # Pseudocode describing roughly what we're trying to achive\r\n    # List of jobs from which it will download the artifacts.\r\n    # dependencies:\r\n        # - setup_conf_staging\r\n    script:\r\n        - *init_ssh\r\n        - *change_file_permissions\r\n        - cp .env.staging .env\r\n        - php artisan deploy devlaraveldeployer.penjelajahtekno.com -s upload -vvv\r\n\r\n    # Define an GitLab environment.\r\n    # This makes GitLab aware of your latest deployments\r\n    # and provides a button to check out the provided url.\r\n    environment:\r\n        name: staging\r\n        url: http://devlaraveldeployer.penjelajahtekno.com\r\n\r\n    # (Optional) Only deploy if we're in the master branch\r\n    # Other branches will only build and test.\r\n    only:\r\n        - master\r\n\r\nproduction:\r\n    stage: deploy\r\n    image: lorisleiva/laravel-docker:latest\r\n    dependencies:\r\n        - setup_conf_production\r\n    script:\r\n        - *init_ssh\r\n        - *change_file_permissions\r\n        - cp .env.production .env\r\n        - php artisan deploy laraveldeployer.penjelajahtekno.com -s upload -vvv\r\n    environment:\r\n        name: production\r\n        url: http://laraveldeployer.penjelajahtekno.com\r\n    when: manual\r\n    only:\r\n        - master\r\n```\r\nThe $SERVER_USER, $SERVER_IP, $DIR_ENV_STAGING, $ENV_STAGING, $DIR_ENV_PRODUCTION, $ENV_PRODUCTION come from Gitlab CI/CD variable that I setup before.\r\n\r\nLog error in staging deploy in this [link](https://gist.github.com/satyakresna/933176bd84ad44dd1dd149050fdf8265)\r\n\r\nI need your solution to fix this problem. Thanks a lot."}}
{"actor":{"display_login":"lorisleiva"}}