codedeploy erases content from directory not affected by deploy - aws-code-deploy

I have 2 private repositories on GitHub for 2 different websites. Both websites run off the same set of auto-scaling servers on Amazon (EC2). I use CodeDeploy to pull the repositories from GitHub and deploy them to the servers, one at a time. This nearly works perfectly.
The issue is that when I deploy one website, the files from the other website are completely erased. Not the folder structure, just the files.
One webisite deploys to /var/www/website1 while the other deploys to /var/www/website2 . The appspec files are:
version: 0.0
os: linux
files:
- source: /
destination: /var/www/website1/
hooks:
BeforeInstall:
- location: /beforeinstall.sh
timeout: 300
runas: root
AfterInstall:
- location: /afterinstall.sh
timeout: 300
runas: root
And
version: 0.0
os: linux
files:
- source: /
destination: /var/www/website2/
hooks:
BeforeInstall:
- location: /beforeinstall.sh
timeout: 300
runas: root
AfterInstall:
- location: /afterinstall.sh
timeout: 300
runas: root
When I deploy "website1", it erases all files from "website2", and vice versa. I have no idea why. Any help would be greatly appreciated.
Before Install for the App (website1)
#/bin/bash
sudo service php-fpm stop
sudo service nginx stop
sudo yum -y update
rm /var/www/app -Rf
rm /usr/share/nginx/html/status.php -Rf
After Install
#/bin/bash
chown app:app /var/www/app/* -Rc
#
find /var/www/app/public_html/files/uploads -type d -exec chmod 777 {} \;
#
cd '/var/www/app'
su app -c 'composer update'
mv /var/www/fairwarning_app/status.php /usr/share/nginx/html/status.php
#
sudo service php-fpm start
sudo service nginx start
Before Install for the API (website2)
#/bin/bash
sudo service php-fpm stop
sudo service nginx stop
sudo yum -y update
rm /var/www/api -Rf
After Install
#/bin/bash
chown api:api /var/www/api/* -Rc
#
cd $'/var/www/api'
su api -c 'composer install'
su api -c 'composer update'
#
sudo service php-fpm start
sudo service nginx start

Looks like AWS CodeDeploy doesn't support simultaneous deployments on the same deployment group. You can track progress and discussion of the issue on their github issue tracker.

Related

Impossible to start Symfony 5 server on Docker container (symfony serve -d)

I trying to create Docker container to contenerized my Symfony 5 application.
I create first a Dockerfile
FROM php:7.4-fpm-alpine
# Update
RUN apk --no-cache update
RUN apk --no-cache add bash git
# Install Node
RUN apk --no-cache add --update nodejs npm
RUN apk --no-cache add --update python3
RUN apk --no-cache add --update make
RUN apk --no-cache add --update g++
# Install pdo
RUN docker-php-ext-install pdo_mysql
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Symfony CLI
RUN curl -sS https://get.symfony.com/cli/installer | bash && mv /root/.symfony/bin/symfony /usr/local/bin/symfony
# WORK DIR
COPY . /var/www/html
WORKDIR /var/www/html
RUN composer update
RUN composer install
RUN npm install
# Start Symfony server on Port 8000
EXPOSE 8000
RUN symfony serve -d
Then I created a docker-compose.yml file (where I simply redirect port 8000 of the container to port 8080 on my machine).
version: '3.8'
services:
php-fpm:
container_name: infolea
build: ./
ports:
- 8080:8000
volumes:
- ./:/var/www/html
Then, I build my image docker-compose build.
Then, I run my image docker-compose up -d.
On my browser, the localhost:8080 link doesn't display anything.
Then I restart the symfony server by typing symfony serve -d on the terminal of my container and on localhost:8080 I can see my application working.
Something is weard, is that when I verified if my server is not started yet on my docker container terminal, I got this :
docker container terminal
What i want, it's to start my Symfony server dirrectly, without retapping symfony serve -d.
How can i do it ?
Try using CMD istead of RUN
CMD ["/usr/local/bin/symfony", "local:server:start" , "--port=8000", "--no-tls"]
see https://docs.docker.com/engine/reference/builder/#cmd

Unable to uninstall nginx on Mac OS X

Output of nginx -v:
nginx version: nginx/1.14.0.
After running brew uninstall nginx or brew remove nginx, it gives error:
Error: No such keg: /usr/local/Cellar/nginx
I have tried :
rm -f /usr/local/sbin/nginx
rm -f -R /usr/local/etc/nginx
rm -r /usr/local/opt/nginx
But still nginx -v giving output: nginx version: nginx/1.14.0
How can I remove the nginx installation?
Check path with which nginx Then, you can remove from that path.
Update your local filesystem db on Mac, this will take of any links in the system,
sudo /usr/libexec/locate.updatedb

kibana-time-plugin downloaded but bower install not working and even kibana not working

I wanted to have a Widget to view and edit the time range from within dashboards of kibana. So after lot of research i found a plugin as Kibana-time-plugin. Ref: https://github.com/nreese/kibana-time-plugin
Currently i am using kibana 5.4.0 in my local. After installing the plugin i have tried "bower install" as per the command specified in git page. But getting an error as :-
$ bower install
/usr/bin/env: ‘node’: No such file or directory
And even if Kibana is not running and giving an error as below attached image:-
kibana5.4.0
Can anyone Guide me on this ?
Thanks in Advance !!!!!!!!!!!!!!!
I think the optimization failures may be due to file permissions, the plugin files need to be accessible by the kibana user. Specifically check this instruction:
Installing plugins with linux packages
Here is a complete script that worked for me. I am new to Kibana and Kibana plugins so any feedback appreciated. Two important notes:
1) I am pulling the zip file from S3 so you will need to edit that.
2) Be sure to restart kibana afterwards and check the logs
#!/bin/bash
# install nodejs and npm
sudo curl --silent --location https://rpm.nodesource.com/setup_6.x | sudo bash -
sudo yum install -y nodejs
sudo npm install -g bower
# copy the plugin zip and unzip it and fix the name
cd /usr/share/kibana/plugins
sudo aws s3 cp s3://<YOUR-BUCKET>/kibana-time-plugin-master.zip .
sudo unzip kibana-time-plugin-master.zip
sudo mv kibana-time-plugin-master kibana-time-plugin
# install the plugin
cd /usr/share/kibana/plugins/kibana-time-plugin
sudo sed -i -e 's/5.0.0/5.4.2/' package.json
sudo chown -R kibana:kibana *
sudo mkdir -p /home/kibana
sudo chown -R kibana:kibana /home/kibana
sudo -u kibana bower install

Deploying ASP.NET 4.* MVC and Web API applications to Linux server

Is there any way of Deploying ASP.NET 4.* MVC and Web API applications to Linux server? I searched and read about Docker but I think that is for .NET 5.
Appreciate your help!
I managed to do that with some bricolage on a Linux-based Docker image.
This helped me a lot: https://github.com/junalmeida/docker-mono-web
Basically, you can host your web application with nginx, but you also need fastcgi-mono-server4.
The dockerfile looks like this:
FROM mono:latest
RUN apt-get update \
&& apt-get install -y \
iproute2 supervisor ca-certificates-mono fsharp mono-vbnc nuget \
referenceassemblies-pcl mono-fastcgi-server4 nginx nginx-extras \
&& rm -rf /var/lib/apt/lists/* /tmp/* \
&& echo "daemon off;" | cat - /etc/nginx/nginx.conf > temp && mv temp /etc/nginx/nginx.conf \
&& sed -i -e 's/www-data/root/g' /etc/nginx/nginx.conf
# this copies nginx configuration files to the proper directory
COPY nginx/ /etc/nginx/
In the link above, the supervisord command is used to start both nginx and fastcgi-mono-server4.
It is configured in a supervisord.conf file like the following, in which the --appconfigdir specifies the root folder of your application:
[supervisord]
logfile=/var/log/supervisor/supervisord.log
logfile_maxbytes = 50MB
nodaemon=true
user=root
[program:mono]
command=fastcgi-mono-server4 --appconfigdir=appconfig --socket=unix --filename=/var/run/mono-fastcgi.sock --printlog --name=mono
user=root
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
[program:nginx]
command=nginx
user=root
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
and launched with this command:
/usr/bin/supervisord -c supervisord.conf
(a folder contains a configuration for nginx, too).

How do you point deployed Meteor app to a new version?

I am specifically talking about an app bundle running on my own server.
I have a Meteor app running using forever in ~/bundle and my git repo is at ~/project. I keep different release bundle tarballs in ~/release.
~/release
|-0.1.0.tar.gz
|-0.1.1.tar.gz
|-0.2.0.tar.gz
After pulling in changes from git and switching to the latest release, I want to bundle my new version and take advantage of hot-code reloading and (hopefully?) keeping client connections alive. What is the best way to do this?
Note: I am also using nginx; so will this affect the process in any way? i.e. will it kill open client connections? do I have to reload nginx after updating to newer app version?
Thanks.
You could use a script like this.
Make sure define your server in your ssh config file, e.g
Host yourserver
User youruser
Port 22
Hostname yourapp.com
IdentityFile ~/.ssh/yourkeyfile.pem
TCPKeepAlive yes
IdentitiesOnly yes
Then you could have a bash script like this:
#!/bin/bash
cd ~/Desktop/yourappdirectory
rm -f ~/Desktop/yourapp.tar.gz
meteor bundle ~/Desktop/yourapp.tar.gz
scp ~/Desktop/yourapp.tar.gz yourserver:~/yourapp.tar.gz
ssh yourserver <<'ENDSSH'
cd ~/
tar -xzf yourapp.tar.gz
sudo rm -rf yourapp
mv bundle yourapp
cd yourapp/programs/server/node_modules
rm -rf fibers
rm -rf bcrypt
sudo npm install fibers#1.0.1
sudo npm install bcrypt
cd ~/yourapp/programs/server/npm/mongo-livedata/main
rm -r mongodb
sudo npm install mongodb#1.4.1
cd ~/
sudo forever stop ~/yourapp/main.js
sudo MONGO_URL=mongodb://user:pass#ip:27017/meteor PORT=3000 ROOT_URL=https://yoursite.com forever start ~/yourapp/main.js
ENDSSH
Then just run the bash and it would upload and deploy your app for you. Just a note I couldn't put a release version in so stuff just uploads to ~/yourapp.tar.gz then unbundles into ~/yourapp
The meteor app would then be hot code reloaded on any clients if they're on the site.

Resources