React-Gitlab actions CI/CD Pipeline & Aws Integration (Elastic Beanstalk-Docker) #Part-2

Bartu Kocakara
3 min readApr 8, 2022

Reference: https://www.youtube.com/watch?v=PGyhBwLyK2U

This article includes 2 topic

Gitlab (Gitlab)

Aws (Elastic Beanstalk-Docker)

1-) Aws > Elastic Beanstalk > Create Application > only edit app name and server(I choose Docker) >Sample Application > press create app button

Now your docker server is ready to serve :)

2-) Check whats going on in the background(you can check virtual servers that are running)

EC2 > Instances > $INSTANCE_NAME

3-) Go to Elastic Beanstalk > $ENV_NAME > upload and deploy > rootfile/templates/dockerrun.aws.public.json > click deploy

  • after deployment is completed > refresh the page > you will see : sample application 1 > open the address > nginx server is ready

4-)We must automatize this process. So we are using Dockerfile in our repository

5-)Also we must make some changes in our gitlab-ci.yaml file.

  • Check your code and push your commits and see stage logs from GitLab pages.
  • Our docker has been built and has been lost as soon as the job is finished.
  • When we want to preserver the docker image we need to save it in a registry.Our projects are not public so doesn’t make sense to using hub.docker.So that reason we need a private registry.

5-)Docker Container Registry

  • Packages & Registries > Container Registry
  • update gitlab-ci.yaml > build docker image like this push your commits and check the logs
  • Let’s check the which tags did we pushed from the stagelogs
  • Lets check our registries again

Packages & registries > container registry : you will see your registered container

6-)Testing the container

Add new stage to gitlab-ci.yaml file >-test >create test stage jobs

7-)Private registry auth

If we want to have a secured application we must protect our registry

In this process, we will use DEPLOY_TOKEN as our key to connect AWS servers

Settings > Repository > Deploy Tokens … Edit Name=AWS, Username=AWS ... read_repository->check, read_registry->check>click ‘Create Deploy Token’ button

On your root directory create and write those files

In our gitlab-ci.yaml file we file add new stage:

  • Deployments > Environments > click on ‘production’ > click on ‘edit’ > update > write your AWS env URL to this field > click ‘save’
  • push your commits and check the logs for be sure about process :)

8-)Post Deployment Test

  • Just add from bottom two jobs to deployment stage

--

--