Skip to content

Build pipeline and deploy a dockerized application to AWS Elastic Beanstalk

Notifications You must be signed in to change notification settings

EneaGozhdari/Deploy_dockerized_app_to_AWS_ElasticBeanstalk

Repository files navigation

GitLab CI Pipeline

This script is a GitLab CI pipeline that automates the process of building, testing, packaging, and deploying a web application. The pipeline is divided into several stages, each of which corresponds to a specific step in the deployment process:

Stages Build - this stage builds the web application using the Node.js runtime environment and the yarn package manager. The pipeline runs the yarn install, yarn lint, yarn test, and yarn build commands to install dependencies, check for code errors, run unit tests, and create a production-ready build of the application. Additionally, it writes the pipeline id as version number to an HTML file.

Package - this stage creates a Docker image of the application and pushes it to a private registry. The pipeline uses the Docker runtime environment to build the image and the GitLab registry to store it. The pipeline also tags the image with the pipeline id as version number.

Dockertest - this stage tests the Docker image by running a curl command to check the version number.

Test - this stage is used to test the application in a staging environment. This can include running integration tests or conducting user acceptance testing.

Deploy - this stage deploys the application to a production environment. It uses the AWS Elastic Beanstalk service to deploy the application. The pipeline copies the Dockerrun file and the auth file to an S3 bucket, and then creates a new version of the Elastic Beanstalk application with the version label being the pipeline id. Finally, it updates the Elastic Beanstalk environment with the new version.

The pipeline also uses a set of environment variables to store authentication information and other configuration settings. These variables are used throughout the pipeline to authenticate with various services and to provide input to the commands that are run. The pipeline also uses tags to group certain steps together.

Tokens and Credentials

The pipeline uses a number of tokens and credentials to authenticate with various services, such as the GitLab registry and the AWS Elastic Beanstalk service.

For example, in the docker image stage, the pipeline uses the DOCKER_USER and DOCKER_PASSWORD variables to authenticate with the GitLab registry and push the Docker image to it. In the deploy to prod stage, the pipeline uses the GITLAB_DEPLOY_TOKEN variable to authenticate with AWS Elastic Beanstalk service and deploy the application.

These tokens and credentials can be defined in the GitLab project settings as "secret variables" and are passed to the pipeline when it runs. This allows the pipeline to authenticate with the various services without the need to hardcode the credentials into the pipeline script.

GitLab Runner

A GitLab runner is a separate service that runs the pipeline and interacts with the GitLab API to receive pipeline jobs and report the pipeline status. The pipeline script is defined in a file called .gitlab-ci.yml in the root of the repository.

You need to set up a GitLab Runner to run the pipeline, this can be done by installing a runner on a machine or using a shared runner provided by GitLab.