Open jasperf opened 2 years ago
Perhaps I need to something like mentioned at https://github.com/deployphp/action/issues/4
name: Deploy
on:
# Run on pushes to `staging` branch only.
push:
paths-ignore:
- '**.md'
branches:
- staging
- '!main'
# Allow manually triggering the workflow. Used for production deploy
workflow_dispatch:
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: [7.4]
node: [12.x]
steps:
- name: Checkout the repo
uses: actions/checkout@v2
- name: PHP setup
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none
tools: composer:v2, deployer, wp-cli
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- name: Deploy to staging
if: ${{ github.ref == 'refs/heads/staging' }}
uses: deployphp/action@master
with:
private-key: ${{ secrets.STAGING_KEY }}
dep: deploy ${{ secrets.ADMIN_USER }} ${{ secrets.ADMIN_EMAIL }} ${{ secrets.ADMIN_PASSWORD }} staging -v
- name: Deploy to production
if: ${{ github.ref == 'refs/heads/main' }}
uses: deployphp/action@master
with:
private-key: ${{ secrets.PRODUCTION_KEY }}
dep: deploy ${{ secrets.ADMIN_USER }} ${{ secrets.ADMIN_EMAIL }} ${{ secrets.ADMIN_PASSWORD }} production
Just not sure how {{ matrix.node }}
and {{ secrets.ADMIN_PASSWORD }}
would load. Also i do not need the password stuff I would think doing all with ssh keys so that part more like the README example:
name: deploy
on: push
# It is important to specify "concurrency" for the workflow,
# to prevent concurrency between different deploys.
concurrency: production_environment
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
- name: Deploy
uses: deployphp/action@v1
with:
private-key: ${{ secrets.PRIVATE_KEY }}
dep: deploy
Secret come from girl ha s had js ssh
@antonmedv Not quite certain what you mean here.. You mean that secrets.PRIVATE_KEY
loads ssh key from Github settings?
Would be nice to have the README example action.yml
updated with staging and master like the other user showed. Especially
steps:
- name: Checkout the repo
uses: actions/checkout@v2
- name: PHP setup
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none
tools: composer:v2, deployer, wp-cli
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
Is useful, but again I wonder what matrix.node
loads..? It loads Node from the setup-node
here?
Yes this can be loaded from the github secrets this is like a special field in settings with the hub
And for simple environment variables can be also just need to assign environment variable from the stickers and of course go to settings of your repository and seconds down.
On using build matrices I found an explanation here https://docs.github.com/en/actions/using-jobs/using-a-build-matrix-for-your-jobs and example
strategy:
matrix:
node: [10, 12, 14]
steps:
# Configures the node version used on GitHub-hosted runners
- uses: actions/setup-node@v2
with:
# The Node.js version to configure
node-version: ${{ matrix.node }}
Thanks to @antonmedv feedback and some more reading I am slowly starting to understand. Thanks Anton!
Got this now
name: deploy
on:
# Trigger the workflow on push or pull request,
# but only for the master branch
# https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions
push:
branches:
- master
pull_request:
branches:
- master
concurrency: production_environment
# on: push
# It is important to specify "concurrency" for the workflow,
# to prevent concurrency between different deploys.
# concurrency: production_environment
jobs:
php-cs-fixer:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
- name: Run PHP CS Fixer
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --config=.php-cs-fixer.dist.php --allow-risky=yes
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Fix styling
deploy:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: [8.1]
node: [14.x]
steps:
- name: Checkout the repo
uses: actions/checkout@v2
- name: PHP setup
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none
tools: composer:v2, deployer
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
run: npm install
run: npm run prod
- name: Deploy
uses: deployphp/action@v1
with:
# Private key for connecting to remote hosts. To generate private key:
# `ssh-keygen -o -t rsa -C 'action@deployer.org'`.
# Required.
private-key: ${{ secrets.PRIVATE_KEY }}
dep: deploy
But hitting
Annotations
1 error
Invalid workflow file: .github/workflows/ci.yml#L64
The workflow is not valid. .github/workflows/ci.yml (Line: 64, Col: 9): Unexpected value 'run' .github/workflows/ci.yml (Line: 65, Col: 9): 'run' is already defined
and it ran right away, which I did not really want... perhaps I need to change the branch as well.
Looks yaml file has some different from different spaces instant before run
@antonmedv was true on some of the spacing but running npm run prod
I still cannot manage. May need to define command here like we can in deploy.yml
but not sure yet how. Now have
name: deploy
on:
# Run on pushes to `staging` branch only.
push:
paths-ignore:
- '**.md'
branches:
- staging
- '!main'
# Allow manually triggering the workflow. Used for production deploy
workflow_dispatch:
concurrency: production_environment
# on: push
# It is important to specify "concurrency" for the workflow,
# to prevent concurrency between different deploys.
# concurrency: production_environment
jobs:
deploy:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: [8.1]
node: [14.x]
steps:
- name: Checkout the repo
uses: actions/checkout@v2
- name: PHP setup
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none
tools: composer:v2, deployer
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
run: npm install
# run: npm run prod
# npm:run:prod:
# - run: 'cd {{release_path}} && npm run prod'
- name: Deploy to staging
if: ${{ github.ref == 'refs/heads/staging' }}
uses: deployphp/action@master
with:
# Private key for connecting to remote hosts. To generate private key:
# `ssh-keygen -o -t rsa -C 'action@deployer.org'`.
# Required.
private-key: ${{ secrets.PRIVATE_KEY }}
dep: deploy
- name: Deploy to production
if: ${{ github.ref == 'refs/heads/master' }}
uses: deployphp/action@master
with:
# Private key for connecting to remote hosts. To generate private key:
# `ssh-keygen -o -t rsa -C 'action@deployer.org'`.
# Required.
private-key: ${{ secrets.PRIVATE_KEY }}
dep: deploy
Checking https://gist.github.com/cagartner/27052b0bccb99c74d8616a943426b390 I might need
- run: npm install
- run: npm run prod
# npm:run:prod:
# - run: 'cd {{release_path}} && npm run prod'
but wonder if I need to change path inside the image and if all this then adds assets to repository. Not sure yet.
Well, perhaps I need to use this block
- name: Commit built assets
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git checkout -B deploy
git add -f public/
git commit -m "Build front-end assets"
git push -f origin deploy
in my ci.yml action as well:
name: deploy
on:
# Run on pushes to `staging` branch only.
push:
paths-ignore:
- '**.md'
branches:
- staging
- '!main'
# Allow manually triggering the workflow. Used for production deploy
workflow_dispatch:
concurrency: production_environment
# on: push
# It is important to specify "concurrency" for the workflow,
# to prevent concurrency between different deploys.
# concurrency: production_environment
jobs:
deploy:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: [8.1]
node: [14.x]
steps:
- name: Checkout the repo
uses: actions/checkout@v2
- name: PHP setup
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none
tools: composer:v2, deployer
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- run: npm install
- run: npm run production
- name: Commit built assets
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git checkout -B deploy
git add -f public/
git commit -m "Build front-end assets"
git push -f origin deploy
- name: Deploy to staging
if: ${{ github.ref == 'refs/heads/staging' }}
uses: deployphp/action@master
with:
# Private key for connecting to remote hosts. To generate private key:
# `ssh-keygen -o -t rsa -C 'action@deployer.org'`.
# Required.
private-key: ${{ secrets.PRIVATE_KEY }}
dep: deploy
- name: Deploy to production
if: ${{ github.ref == 'refs/heads/master' }}
uses: deployphp/action@master
with:
# Private key for connecting to remote hosts. To generate private key:
# `ssh-keygen -o -t rsa -C 'action@deployer.org'`.
# Required.
private-key: ${{ secrets.PRIVATE_KEY }}
dep: deploy
Question remains though... if I build these assets on the image/github do these github acctions including push also happen on Github?
@antonmedv Do you build locally? Or do you add it to deploy.yml
and bujld npm assets on the server?
Yes you can simply Luther and then upload it to destination this is what I do and you can do it both ways I prefer to do from the plural
@antonmedv think you made typo there. What do you mean by "Luther then upload it to destination"? You build on Github using a Github action like I am suggesting here? I mean like:
npm install
and npm run production
deploy.yml
there including:
Or do you do more on Github action?
deploy.yml
now with npm run prod
included and ci.yml
not in use:
import:
- recipe/laravel.php
- contrib/php-fpm.php
- contrib/npm.php
config:
application: 'our-app'
remote_user: forge
deploy_path: '~/{{hostname}}'
repository: 'git@github.com:app/our-app.git'
php_fpm_version: '8.0'
keep_releases: '10'
shared_files:
- '.env'
- '.transip_private_key'
- 'storage/app/exact.api.json'
shared_dirs:
- 'bootstrap/cache'
- 'public/uploads'
- 'public/published'
- 'storage/framework/cache'
- 'storage/framework/sessions'
- 'storage/framework/views'
- 'storage/logs'
- 'storage/tls'
- 'storage/app/downloads'
- 'storage/app/modules'
- 'storage/app/public'
writable_dirs:
- 'public/uploads'
- 'public/published'
- 'storage/framework/cache/data'
- 'storage/logs'
- 'storage/tls'
- 'storage/app/downloads'
- 'storage/app/modules'
- 'storage/app/public'
hosts:
prod:
hostname: 'site.com'
staging:
hostname: 'staging.site.com'
tasks:
deploy:
- deploy:prepare
- deploy:vendors
- artisan:storage:link
- artisan:view:cache
- artisan:config:cache
- artisan:optimize
- artisan:migrate
- npm:install
- npm:run:prod
- artisan:queue:restart
- artisan:horizon:terminate
- deploy:publish
npm:run:prod:
- run: 'cd {{release_path}} && npm run prod'
after:
deploy:symlink: php-fpm:reload
deploy:failed: deploy:unlock
Found some code at https://gist.github.com/cagartner/27052b0bccb99c74d8616a943426b390 for building including npm
and creating a temporary commit. Can then add your deployment action after I think:
name: CD
on:
push:
branches: [ production ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
token: ${{ secrets.PUSH_TOKEN }}
- name: Set up Node
uses: actions/setup-node@v1
with:
node-version: '12.x'
- run: npm install
- run: npm run production
- name: Commit built assets
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git checkout -B deploy
git add -f public/
git commit -m "Build front-end assets"
git push -f origin deploy
- name: Deploy
uses: deployphp/action@v1
with:
# Private key for connecting to remote hosts. To generate private key:
# `ssh-keygen -o -t rsa -C 'action@deployer.org'`.
# Required.
private-key: ${{ secrets.PRIVATE_KEY }}
dep: deploy
Well it is at least closer again. Just do not follow git add -f public/
... Do see it at https://github.com/henrylemmon/laravel-8-fortify-auth-with-tests/blob/master/.github/workflows/main.yml as well though. And I could keep deploy.yml
for general build details in the repository as well:
import:
- recipe/laravel.php
- contrib/php-fpm.php
- contrib/npm.php
config:
application: 'app-app'
remote_user: forge
deploy_path: '~/{{hostname}}'
repository: 'git@github.com:app/app-app.git'
php_fpm_version: '8.0'
keep_releases: '10'
shared_files:
- '.env'
- '.transip_private_key'
- 'storage/app/exact.api.json'
shared_dirs:
- 'bootstrap/cache'
- 'public/uploads'
- 'public/published'
- 'public/images'
- 'public/downloads'
- 'storage/framework/cache'
- 'storage/framework/sessions'
- 'storage/framework/views'
- 'storage/logs'
- 'storage/tls'
- 'storage/app/downloads'
- 'storage/app/modules'
- 'storage/app/public'
writable_dirs:
- 'public/uploads'
- 'public/published'
- 'storage/framework/cache/data'
- 'storage/logs'
- 'storage/tls'
- 'storage/app/downloads'
- 'storage/app/modules'
- 'storage/app/public'
hosts:
prod:
hostname: 'app.com'
staging:
hostname: 'staging.app.com'
tasks:
deploy:
- deploy:prepare
- deploy:vendors
- artisan:storage:link
- artisan:view:cache
- artisan:config:cache
- artisan:optimize
- artisan:migrate
# - npm:install
# - npm:run:prod
- artisan:queue:restart
- artisan:horizon:terminate
- deploy:publish
# npm:run:prod:
# - run: 'cd {{release_path}} && npm run prod'
after:
deploy:symlink: php-fpm:reload
deploy:failed: deploy:unlock
When I use this action, can I keep
deploy.yml
:in the root of the Laravel/Vue project?
Two, where do we add the secrets?
Three, will the action
run npm install
andnpm run prod
inside the image as well? I mean, I can add this to the deploy.yml but better to get that done in the image/ on Github and then deploy like we do now. Only now we build locally.Upvote & Fund