Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automate code deploy from Git lab to AWS EC2 instance

We're building an application for which we are using GitLab repository. Manual deployment of code to the test server which is Amazon AWS EC2 instance is tedious, I'm planning to automate deployment process, such that when we commit code, it should reflect in the test instance.

from my knowledge we can use AWS code-deploy service to fetch the code from GitHub. But code deploy service does not support GitLab repository . Is there a way to automate the code deployment process to AWS Ec2 instance through GitLab. or Is there a shell scripting possibility to achieve this? Kindly educate me.

like image 237
Vibin Guevara Avatar asked Apr 05 '16 21:04

Vibin Guevara


People also ask

Can GitLab deploy to AWS?

GitLab provides Docker images with the libraries and tools you need to deploy to AWS. You can reference these images in your CI/CD pipeline. If you're using GitLab.com and deploying to the Amazon Elastic Container Service (ECS), read about deploying to ECS.

Can GitLab deploy code Cicd?

GitLab CI/CD can automatically build, test, deploy, and monitor your applications by using Auto DevOps.


1 Answers

One way you could achieve this with AWS CodeDeploy is by using the S3 option in conjunction with Gitlab-CI: http://docs.aws.amazon.com/codepipeline/latest/userguide/getting-started-w.html

Depending on how your project is setup, you may have the possibility to generate a distribution Zip (Gradle offers this through the application plugin). You may need to generate your "distribution" file manually if your project does not offer such a capability.

Gitlab does not offer a direct S3 integration, however through the gitlab-ci.yml you would be able to download it into the container and run the necessary upload commands to put the generated zip file on the S3 container as per the AWS instructions to trigger the deployment.

Here is an example of what your brefore-script could look like in the gitlab-ci.yml file:

before_script:
  - apt-get update --quiet --yes
  - apt-get --quiet install --yes python
  - pip install -U pip
  - pip install awscli

The AWS tutorial on how to use CodeDeploy with S3 is very detailed, so I will skip attempting to reproduce the contents here.

In regards to the actual deployment commands and actions that you are currently performing manually, AWS CodeDeploy provides the capability to run certain actions through scripts defined in the app-spec file depending on event hooks for the application:

  • http://docs.aws.amazon.com/codedeploy/latest/userguide/writing-app-spec.html
  • http://docs.aws.amazon.com/codedeploy/latest/userguide/app-spec-ref.html
  • http://docs.aws.amazon.com/codedeploy/latest/userguide/app-spec-ref-hooks.html

I hope this helps.

like image 92
autronix Avatar answered Oct 18 '22 00:10

autronix