I am trying to deploy Laravel on AWS using code deploy, I have attached a sample yml file as well.
As the hook:BeforeInstall: will configure the php, mysql and other configuration that will be needed to run the Laravel Application. I need to know whenever the deployment is made will that hook trigger each time? as I don't want to install the php mysql each time, what I want to do is it should run only on first time and for all other deployments it should not install configurations again.
version: 0.0
os: linux
files:
- source: /*
destination: /var/www/html/my/directory
hooks:
BeforeInstall:
- location: scripts/install_dependencies
timeout: 300
runas: root
- location: scripts/start_server
timeout: 300
runas: root
for first time install php and mysql you can write shell script
for second time write another shell script
each time it call different shell script file....
you can refer this one...
where there is yaml file and script folder contain sh files
https://github.com/enzyme-ops/laravel-code-deploy-template
Related
I have a workflow in GitHub that will execute a shell script, and inside this script I need to use gsutil
In my workflow yml-file I have the following steps:
name: Dummy Script
on:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
environment: alfa
env:
_PROJECT_ID: my-project
steps:
- uses: actions/checkout#v2
- name: Set up Cloud SDK for ${{env._PROJECT_ID}}
uses: google-github-actions/setup-gcloud#master
with:
project_id: ${{env._PROJECT_ID}}
service_account_key: ${{ secrets.SA_ALFA }}
export_default_credentials: true
- run: gcloud projects list
- name: Run script.sh
run: |
path="${GITHUB_WORKSPACE}/script.sh"
chmod +x $path
sudo $path
shell: bash
And the script looks like:
#!/bin/bash
apt-get update -y
gcloud projects list
The 2nd step in yml (run: gcloud projects list) works as expected, listing the projects SA_USER have access to.
But when running the script in step 3, I get the following output:
WARNING: Could not open the configuration file: [/root/.config/gcloud/configurations/config_default].
ERROR: (gcloud.projects.list) You do not currently have an active account selected.
Please run:
$ gcloud auth login
to obtain new credentials.
If you have already logged in with a different account:
$ gcloud config set account ACCOUNT
to select an already authenticated account to use.
Error: Process completed with exit code 1.
So my question is:
How can I run a shell script file and pass on the authentication I have for my service account so I can run gcloud commands from a script file?
Due to reasons, it's a requirement that the script file should be able to run locally on developers computers, and from GitHub.
The problem seemed to be that the environment variables were not inherited when running with sudo. There are many ways to work around this, but I was able to confirm that it would run with sudo -E. Of course, if you don't need to run with sudo, you should remove it, but I guess it's necessary.
(The reproduction code was easy for me to reproduce it. Thanks)
I try to skip a directory with yaml in Google Cloud, my app.yaml is:
runtime: php55
api_version: 1
threadsafe: true
skip_files:
- assets/
handlers:
- url: /.*
script: index.php
But, it doesn't work, Do you know which is wrong in my code?
This is the correct syntax and worked on my project with the same php version, api version and thread safety.
Did you deploy and wait a few minutes for it to take effect? It usually takes 3 minutes after the deploy completion for the changes to be in effect.
You can check which versions of your application are running with gcloud app versions list.
Also, if you're using local development (dev_appserver.py), then the skip_files directive will be ignored and they will be served normally.
Problem: I am having difficulty deploying the Jekyll build folder to an FTP server via Wercker.
I've been using Wercker for continuos integration of a Jekyll site I'm working on. Using the script below, The build process: jekyll build and jekyll doctor appear to be working as intended.
My deploy step should upload the "_site" folder to my FTP server. I'm currently using duleorlovic's ftp-deploy wercker step. It's currently uploading the entire directory, instead of just the build folder.
However, Jekyll uses the /_site folder as the directory for where the site gets built to ... how could I limit my upload to just the /_site build folder?
Thanks.
Current wercker.yml as follows:
# Wercker Configuration
# continuous delivery platform that helps software developers
# build and deploy their applications and microservices
box: ruby
build:
steps:
# Install dependencies
- bundle-install
# Execute jeykyll doctor command to validate the
# site against a list of known issues.
- script:
name: jekyll doctor
code: bundle exec jekyll doctor
- script:
name: jekyll build
code: bundle exec jekyll build --trace
deploy:
steps:
- duleorlovic/ftp-deploy:
destination: $FTP_SERVER
username: $FTP_USERNAME
password: $FTP_PASSWORD
timeout: 15
remote-file: remote.txt
Solved the question.
Apparently Worker offers an environment variable called $WERCKER_OUTPUT_DIR. This directory is the folder that gets piped to the deploy step when the build step passes. If not passed anything, the deploy step just used the root directory (aka not your build folder).
The working wercker.yml contains the jekyll build step as follows:
- script:
name: jekyll build
code: bundle exec jekyll build --trace --destination "$WERCKER_OUTPUT_DIR"
I wasn't able to find much for Wercker docs on the matter, since it seems like thier in transition between versions, but I found the solution in an example of how to use wercker.
You can see the example of using the Output Directory in their guide How Wercker Works.
By passing the cwd: argument to the step you can change the working directory (according to the wercker doc):
deploy:
steps:
- duleorlovic/ftp-deploy:
cwd: _site/
destination: $FTP_SERVER
username: $FTP_USERNAME
password: $FTP_PASSWORD
timeout: 15
remote-file: remote.txt
I have a Node.js application which is being automatically deployed to Amazon Web Service through Codeship using the CodeDeploy AWS deployment system.
During the deployment process I've set in my appspec.yml for the currently running web application to be stopped. Once the deployment is complete, I want the web application to be started up again.
os: linux
files:
- source: /
destination: /var/www/app2
hooks:
AfterInstall:
- location: bash_scripts/stop_forever.sh
runas: ec2-user
ApplicationStart:
- location: bash_scripts/start_forever.sh
runas: ec2-user
However I've not yet been able to have either of these scripts to be called successfully from the appspec.yml file during a deployment.
The current error I'm seeing in the AWS deployment agent log is
Error CodeScriptMissing
Script Name /var/scripts/stop_forever.sh
MessageScript does not exist at specified location: /var/scripts/stop_forever.sh
Log TailLifecycleEvent - ApplicationStop
This seems to refer to an older version of the appspec.yml file which was attempting to run these scripts in a different location. Even though I've changed the contents of the appspec.yml file in the deployed package, this error message remains the same on each deploy.
In addition to appspec.yml file listed above, I've also tried making the following changes:
Not listing a runas parameter for each hook
Referencing a script inside the deployed directory
Referencing a script outside the deployed directory
Having a version parameter initially set to 0.0
Unfortunately there is very little online in terms of appspec.yml troubleshooting, other than the AWS documentation.
What very obvious thing I am doing wrong?
The ApplicationStop hook is being called from the previously installed deployment before trying to run the current deployment appspec.yml file.
In order to prevent this from happening you'll have to remove any previously installed deployment from the server.
Stop the code deploy agent - sudo service codedeploy-agent stop
clear all deployments under /opt/codedeploy-agent/deployment-root
Restart the code deploy agent - sudo service codedeploy-agent start
There is another way documented in the AWS developer forums, which I think is preferable.
Use the --ignore-application-stop-failures option with the CLI tool while doing the deployment, it worked perfectly for me.
Example taken from the forum:
aws deploy create-deployment --application-name APPLICATION --deployment-group-name GROUP --ignore-application-stop-failures --s3-location bundleType=tar,bucket=BUCKET,key=KEY --description "Ignore ApplicationStop failures due to broken script"
https://forums.aws.amazon.com/thread.jspa?threadID=166904
I've created a PHP script that generates a local.xml file for Magento with the required database settings and credentials. I need to run this after the application is deployed; however I cannot seem to figure out a way to do so. My understanding is that I need to create a .config file inside of a .ebextensions directory. Anyone have a solution?
Technically Josh is not correct. According to the documentation (http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#customize-containers-format-commands): the commands section .. "The commands are processed in alphabetical order by name, and they run before the application and web server are set up and the application version file is extracted."
The closest I am aware of is the "container_commands" section which "The commands in container_commands are processed in alphabetical order by name. They run after the application and web server have been set up and the application version file has been extracted, but before the application version is deployed."
I don't know of a way to truly run a script post deployment (which is why I was here looking for that answer).
Elastic Beanstalk will look files under /opt/elasticbeanstalk/hooks/appdeploy/post directory to run after deployment.
So you can make use of this and do:
commands:
create_post_dir:
command: "mkdir /opt/elasticbeanstalk/hooks/appdeploy/post"
ignoreErrors: true
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/job_after_deploy.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
/var/app/current
** run your php script here **
Yup, .ebextensions are what you are looking for. To see how to bundle the source, take a look at the sample applications. There is a PHP one you can look at as well.
For more info on .ebextensions, take a look at this page.
Here's an example of a custom command. This could go in a file called sample.config within the .ebextensions directory:
commands:
success_command:
command: echo "this will be ran after launching"
Be careful if you copy and paste YAML and double check the format. You can also use JSON which follows the similar format.