AWS Elastic Beanstalk Post Deploy Script - ruby-on-rails

I'm attempting to add a post deployment script to my Elastic Beanstalk. I've read a few blog posts (read the references) that reference adding a config file to the .elasticbeanstalk directory. The config file is supposed to create a shell script and copy it to the directory:
/opt/elasticbeanstalk/hooks/appdeploy/post
In my .elasticbeanstalk folder, I have the following files:
config.yml
branch-defaults:
staging:
environment: env-name
global:
application_name: app-name
default_ec2_keyname: aws-eb
default_platform: 64bit Amazon Linux 2015.03 v1.3.1 running Ruby 2.2 (Passenger Standalone)
default_region: us-west-2
profile: eb-cli
sc: git
test.config (the config I added to test out how the post deployment script works):
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/01_test.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
# This is my test shell script
After I run eb deploy though, the shell script doesn't get copied to the above directory. My /opt/elasticbeanstalk/appdeploy/post directory is empty. The .elasticbeanstalk folder is correct in the /var/app/current/ directory. I also can not see anything in the log files that references the new script or an error. I've checked eb-tools.log, eb-activity.log, cron, and grepped all logs for keywords around those files. Still, no luck.
Thanks in advance for any help/suggestions!
References:
https://forums.aws.amazon.com/thread.jspa?threadID=137136
http://www.dannemanne.com/posts/post-deployment_script_on_elastic_beanstalk_restart_delayed_job

The right place to drop your config file is .ebextensions directory in your app and not . elasticbeanstalk. You should then see your shell script in the /opt/elasticbeanstalk/hooks/appdeploy/post directory.
As noted in the forum post
"Dropping files directly into the hooks directories is risky as this is not the documented method, is different in some containers and may change in the future"

Related

Serverless - Service configuration is expected to be placed in a root of a service (working directory)

I have this warning on GitHub Action:
Serverless: Deprecation warning: Service configuration is expected to be placed in a root of a service (working directory). All paths, function handlers in a configuration are > resolved against service directory".
Starting from next major Serverless will no longer permit configurations nested in sub directories.
Does it mean I have to put serverless.yml (Service configuration) in the working directory?
If yes, which one is the working directory?
.github/workflows/deploy.yml
service: myservice
jobs:
deploy:
# other steps here #
- name: Serverless
uses: serverless/github-action#master
with:
args: deploy --config ./src/MyStuff/serverless.yml
I store the serverless.yml in that path because it is related to Stuff.
I want to use multiple serverless.yml.
For AnotherStuff I will create src/AnotherStuff/serverless.yml .
So, what is the error, and the right way to do it?
[edit 21/02/2022]
I'm using the following workaround.
In GitHub Actions I have this job step in my build:
- name: Serverless preparation
run: |
# --config wants the serverless files in the root, so I move them there
echo move configuration file to the root folder
mv ./serverless/serverless.fsharp.yml ./serverless.fsharp.yml
Essentially, they want the file in the root folder... I put the file in the root folder.

Docker, how to COPY docker-specific versions of files to WORKDIR

Can Docker's COPY or RUN cp be used in a Dockerfile to overwrite a default config file with a docker-specific version of the file?
In a Rails project, our config folder has multiple versions of database.yml for different environments:
# projectname/config/
database.yml # an unused default placeholder
database_for_docker_2.yml
database_for_vagrant.yml
For different dev environments (vagrant+virtualbox vs docker) during initialization of the machine/container we copy the appropriate version of the .yml to database.yml
In the Dockerfile, after this section:
WORKDIR /my_app
RUN bundle install
COPY . /my_app
we tried:
RUN cp ./config/database_docker_2.yml /my_app/config/database.yml
but the file does not seem to be copied, the default version of database.yml is used when we spin up the container.
we then tried:
COPY ./config/database_docker_2.yml /my_app/config/database.yml
the file still does not seem to be copied, the default version of the file gets used when we spin up the container.
What DOES work is adding another entry to the volume section of docker-compose.yml specifically for that one file:
volumes:
- .:/my_app
- ./config/database_docker_2.yml:/my_app/config/database.yml
but we prefer to manage the placement of env-specific versions of files in the Dockerfile (as opposed to littering the docker-compose.yml with such env-specific files)
The command COPY ./config/database_docker_2.yml /my_app/config/database.yml probably works, there is no reason it shouldn't assuming the source exists.
What I suspect happens, is that when you are testing it, you already have a volume with .:/my_app, which then shows you the local folder, and not the in-container folder.
Run it without the volume, and I believe you will in fact see that it copied it into the container, as you intended.
On a side note:
If you are not yet locked in your way of handling this multiple database config, I would consider re-evaluating your situation, and trying to find a solution that does not require you to change database.yml for each environment. One way, would be to have the database.yml use an environment variable (usually DATABASE_URL) and then you have one docker-compose for all, and one database.yml for all, and you only configure environment with environment variables.

DreamFactory how to disable wrapper "resource" in docker container

I'm using DreamFactory REST API in a Docker container and I need to disable wrapper "resource" in payload. How can I achieve this?
I have replaced the following in all of these four files:
opt/bitnami/dreamfactory/.env-dist
opt/bitnami/dreamfactory/vendor/dreamfactory/df-core/config/df.php
opt/bitnami/dreamfactory/installer.sh
bitnami/dreamfactory/.env
DF_ALWAYS_WRAP_RESOURCES=true
with:
DF_ALWAYS_WRAP_RESOURCES=false
but this doesn't fix my problem.
The change you describe is indeed the correct one as found in the DreamFactory wiki. Therefore I suspect the configuration has been cached. Navigate to your DreamFactory project's root directory and run this command:
$ php artisan config:clear
This will wipe out any cached configuration settings and force DreamFactory to read the .env file in anew. Also, keep in mind you only need to change the .env file (or manage your configuration variables in your server environment). Those other files won't play any role in configuration changes.

Access to the path 'C:\inetpub\wwwroot\App_Data\TEMP\PluginCache' is denied. Amazon AWS Beanstalk

I'm trying to setup an Umbraco website on Amazon AWS Beanstalk using the AWS Toolkit for Visual studio 2017, I have added the .ebextensions folder and inside my config file
{
"containercommands": {
"01-changeperm": {
"command": "icacls \"C:/inetpub/wwwroot/App_Data\" /grant IIS_IUSRS:(OI)(CI)"
}
}
}
I have also tried DefaultAppPool instead of IIS_IUSRS as per this post How can I set folder permissions for elastic beanstalk windows application? and I have also tried
commands:
create_default_website_folder:
command: if not exist "C:\inetpub\wwwroot" mkdir "C:\inetpub\wwwroot"
update_iis_user_permissions:
command: Icacls.exe "C:\inetpub\wwwroot" /grant IIS_IUSRS:(OI)(CI)F
from this post https://aws.amazon.com/blogs/devops/run-umbraco-cms-with-flexible-load-balancing-on-aws/ along with many other post, but none work, does anyone know what else I need to do as I'm constantly getting the following error.
Access to the path 'C:\inetpub\wwwroot\App_Data\TEMP\PluginCache' is
denied.
You can visit this page to see what Umbraco needs: https://our.umbraco.com/documentation/Getting-Started/Setup/Server-Setup/permissions
Essentially all of these need modify permissions to all of the folders in your umbraco installation:
IUSR
IIS_IUSRS
IIS apppool\[appoolname]
Wow! your post is really help me (and https://thedeveloperspace.com/granting-write-access-to-asp-net-apps-hosted-on-aws-beanstalk/ and ASP.Net Core at AWS EBS - write permissions and .ebextensions )
In my scenario my local folder for temp files is at
C:\inetpub\wwwroot\Temp
So I reedit your command to
commands:
create_default_website_folder:
command: if not exist "C:\inetpub\wwwroot\Temp" mkdir "C:\inetpub\wwwroot\Temp"
container_commands:
01storage_permissions:
command: "icacls C:\\inetpub\\wwwroot\\Temp /grant DefaultAppPool:(OI)(CI)F"
Then I have permission to use my target folder thanks for the mkdir command.
Becuase your Access to the path 'C:\inetpub\wwwroot\App_Data\TEMP\PluginCache' is denied.
May be your config must be specific folder like this ?
commands:
create_default_website_folder:
command: if not exist "C:\inetpub\wwwroot\App_Data\TEMP\PluginCache" mkdir "C:\inetpub\wwwroot\App_Data\TEMP\PluginCache"
update_iis_user_permissions:
command: Icacls.exe "C:\inetpub\wwwroot\App_Data\TEMP\PluginCache" /grant IIS_IUSRS:(OI)(CI)F

How to copy a file or jar file that has built from jenkins to a diff host server

Am having a jenkins job where am building a jar file. after the build is done I need to copy that jar file to a different server and deploy it there.
Am trying this yml file to achieve the same but it is looking for the file in the different server other than the jenkins server.
---
# ansible_ssh_private_key_file: "{{inventory_dir}}/private_key"
- hosts: host
remote_user: xuser
tasks:
- service: name=nginx state=started
become: yes
become_method: sudo
tasks:
- name: test a shell script
command: sh /home/user/test.sh
tasks:
- name: copy files
synchronize:
src: /var/jenkins_home/hadoop_id_rsa
dest: /home/user/
could you please suggest is there any other way or what could be approach to copy a build file to the server using jenkins to deploy.
Thanks.
Hi as per my knowledge you can use Publish Over ssh plugin in jenkins. actually i am not clear about your problem. but hoping that this can help you. plugin details: https://wiki.jenkins-ci.org/display/JENKINS/Publish+Over+SSH+Plugin if it wont help you, please comment. can you please more specific. (screen shot if possible)
Use remote ssh script in the build step no plug in is required
scp –P 22 Desktop/url.txt user#192.168.1.50:~/Desktop/url.txt
Setup passwords less authentication use the below link for help
https://www.howtogeek.com/66776/how-to-remotely-copy-files-over-ssh-without-entering-your-password/

Resources