Automate code deployment from Git lab to AWS EC2 instance

We are creating an application for which we use the GitLab repository. Manually deploying code to a test server that an Amazon AWS EC2 instance is tiring, I plan to automate the deployment process, so when we execute the code, it should reflect in the test instance.

To my knowledge, we can use AWS code-deploy to retrieve code from GitHub. But the code deployment service does not support the GitLab repository. Is there a way to automate the process of deploying code with an AWS Ec2 instance through GitLab. or is there a possibility of shell scripts to achieve this? Please enlighten me.

+5
source share
1 answer

One way to achieve this with AWS CodeDeploy is to use 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 set up, you may be able to generate a Zip distribution (Gradle offers this through the application plugin). You may need to create your โ€œdistributionโ€ file manually if your project does not offer such an opportunity.

Gitlab does not offer direct S3 integration, however through gitlab-ci.yml you can load it into the container and execute the necessary download commands to place the created zip file in the S3 container in accordance with AWS instructions to initiate the deployment.

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

 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 trying to play the content here.

Regarding the actual deployment commands and actions that you are currently executing manually, AWS CodeDeploy provides the ability to run specific actions using scripts defined in the application file, depending on the event bindings for the application:

Hope this helps.

+7
source

Source: https://habr.com/ru/post/1246506/


All Articles