How to push a git submodule to AWS Elastic Beanstalk? - django

I have a repo named ld with a submodule named ldapp, which is a Django project. I want to push the Django project ldapp to elastic beanstalk, but I get the warning following warning when running eb init:
Warning: Your directory has not been initialized as a Git repository.
To create a local Git repository, run "git init" and then re-run the
"eb init" command.
If I continue on and run eb push I get:
git: 'aws.push' is not a git command. See 'git --help'. Cannot run
aws.push for local repository HEAD:
The way git structures submodules is it actually has the .git of the submodule be a file, not a directory. The following is the contents of the file ldapp/.git:
gitdir: ../.git/modules/ldapp
This file tells git to retrieve ldapp's versions from ld's .git directory. Since the .git versioning of ldapp is not present within ldapp itself (but rather within ld's .git), running eb init and eb push fail. How do I fix this?

I don't think you can. I had to git clone the submodule to get back a standalone Git repository.

Related

Django elastic beanstalk CLI deployment failure after adding .env files to gitignore

I'm new to Django/EB/Git and been working on a django project and have successfully separated my setttings and separated .env files for both development and production which all works as expected and deployed- see the following project structure:
Project Structure
project root
myapp
settings
__init__
base.py
dev.py
prod.py
.env.dev
.env.prod
.gitignore
manage.py
requiremnts.txt
However the moment I add my my .env files to the .gitignore file I now received the following error with deployment within eb logs (cfn-init-cmd.log):
.gitignore
# Elastic Beanstalk Files
.elasticbeanstalk/*
!.elasticbeanstalk/*.cfg.yml
!.elasticbeanstalk/*.global.yml
.env.dev
.env.prod
Error: eb logs (cfn-init-cmd.log)
FileNotFoundError: [Errno 2] No such file or directory: '.env.prod'
If i remove .env.prod from the .gitignore file then my project deploys successfully.
Moreoever, I read online that might be due to me git adding and comitting the .env.prod file to the repo however believe I have also excluded git add/commit when I started fresh and re-created the git repo with the following command (commands run on local project):
git add --all -- :!.env.dev :!.env.prod
git commit -m "Initial commit"
Followed by:
eb deploy myproject-env
See my .ebextensions config file as follows:
.ebextensions/django.config
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: myproject.wsgi:application
aws:elasticbeanstalk:application:environment:
DJANGO_SETTINGS_MODULE: "myproject.settings.prod"
aws:elasticbeanstalk:environment:proxy:staticfiles:
"/static": "static/"
packages:
yum:
python3-devel: []
mariadb-devel: []
container_commands:
01_collectstatic:
command: "source /var/app/venv/staging-LQM1lest/bin/activate && python manage.py collectstatic --noinput"
02_migrate:
command: "source /var/app/venv/staging-LQM1lest/bin/activate && python manage.py migrate --noinput"
leader_only: true
I was not sure if I'm supposed to add any git commands to my .ebextensions config but assumed it's just to be done on local git repo and then push to github, I have also tried to deploy with and without codecommit but made no difference to the above.
I have spent a about a week figuring this all out and finally being able to deploy and this I believe was supposed to be the very last step adding .env files to .gitignore file, I'm just not sure what I'm missing or have done something I correctly with the git repo.
Elastic beanstalk use .gitignore file if .ebignore file does not exist. So you can use both for your file management.
AWS doc says:
You can tell the EB CLI to ignore certain files in your project
directory by adding the file .ebignore to the directory. This file
works like a .gitignore file.
...
If .ebignore isn't present, but .gitignore is, the EB CLI ignores
files specified in .gitignore. If .ebignore is present, the EB CLI
doesn't read .gitignore.
When .ebignore is present, the EB CLI doesn't use git commands to
create your source bundle. This means that EB CLI ignores files
specified in .ebignore, and includes all other files. In particular,
it includes uncommitted source files.

git: 'remote-https' is not a git command. See 'git --help'

I have been trying to clone my repository and it shows the following error:-
git: 'remote-https' is not a git command. See 'git --help'
Here is my:-
Clone from
https://github.com/NavyaThakur/django-project1
To directory
C:\Users\91933\github\django-project1
I tried reinstalling github desktop but no use.
Please help me through this
Try git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY
so for you git clone https://github.com/NavyaThakur/django-project1
Git Clone Documentation
This error means your git executable was not built with ssl and/or libcurl.
From experience this seems to be a problem on some RedHat based distributions.
If you have admin access just make use you install the correct git client. If not you will have to build git yourself or install from a repository into your user account (both of which are not trivial, sorry)

Is it good practice to add .git folder to Github?

After i entered git init I have directory D:myproject\.git
Is it good to add .git folder it in Github or should i add it in .gitignore?
You should not worry about .git folder. It contains git internals and all information in your repository like commits, branches and blobs. So .git is a repository itself and is handled automatically.
If you are in the root directory of your app and you do git init command what happens is that the command says initialize this directory and everything below it as a git repository. And it will set up a local repository for you on your machine.
Local repository on your machine allows git to track version changes in our files. Once we are happy with all those changes and our files then we push them to a remote repository on GitHub.
And you don't have to add your .git folder in .gitignore file.

Google source repository integration

I have a git repository with multiple branches which I wanted to push to google source repository. But it takes only a particular branch of the repository. How can I create a branch on google source repository and push code to that branch only ?
create a new branch:
git checkout -b branch_name
edit, add and commit your files.
then push the branch to the remote:
git push -u origin branch_name
assuming you have already added it as remote.
see git checkout & git push.

Docker & Amazon Beanstalk - Deploy an Angular application

I am trying to deploy a dist folder that is generated with versioning by Gulp using a Dockerfile and with Amazon EB.
This fails when I run eb deploy with:
COPY dist /var/www/html dist: no such file or directory. Check snapshot logs for details. Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/03build.sh failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.
Is this because the dist directory is not under source control? If so, what is the best way to transfer the dist directory up to EB whilst still using my docker file to deploy and configure the application?
Below is my Dockerfile:
FROM nimmis/apache-php5
COPY dist /var/www/html
WORKDIR /var/www/html
EXPOSE 80
If you really want the dist files in your docker image then install gulp and run the command to generate the dist folder within the Dockerfile.
See the RUN command for Dockerfiles
I think my understanding of eb deploy was the issue. Answer is to zip the dist directory, along with other files using a bash script and create my own artifact for the config.yml file:
e.g.
dist (application files)
config (php.ini and 000-default.conf)
Dockerfile
Then add the directory to the config.yml:
deploy:
artifact: dist.zip
I was then able to write a bash script to create a version number label and then deploy to Beanstalk:
eb deploy --staged --label {version_number}