Skip to content

Accelerating Collaboration and Deployment with Docker, Terraform and Jenkins: DevOps Project for the Website 'Explore California'

Notifications You must be signed in to change notification settings

itsAditiSaraswat/DevOps-project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 

Repository files navigation

Explore California

DevOps Project


   
Objective and Approach - Bridge the gap between production and development by containerizing the website ‘Explore California’ with Docker and Docker Compose
- Unit and Integration testing using RSpec, Capybara and Selenium
- Rapidly deploy a working instance of the website into the cloud (AWS S3) using Terraform
- Build and deploy the website using CICD pipeline with Jenkins
Impact - All environments consistent using Docker/ Docker Compose
- Deploys into production automated via Terraform
- Production deploys 100% automated through CI

Primary Technology: Docker, Docker Compose, RSpec, Capybara, Selenium, AWS S3, Terraform, Jenkins



1. Testing Locally with Docker

1.1 Installing Docker

sudo apt-get install docker-engine -y

1.2 Writing Dockerfile

vim Dockerfile 1 docker build --tag website . 2 docker run --publish 80:80 website 3 4

1.2 Writing Docker Compose manifest

vim docker-compose.ymlo 5 docker-compose up 6 4

2. Testing the App with RSpec, Capybara, and Selenium

To write some automated tests for the website, we will use RSpec, Capybara, and Selenium.

RSpec is a Ruby-based testing framework. It is a domain-specific language or DSL.
Capybara is a tool that let's you use a web driver to create a browser and interact with the website.
Selenium is a web driver that spins up a real web browser and tests against whatever the web browser sees.

2.1 Setting up the test

Create a folder spec. Create another folder unit within spec. Now, create a file page_spec.rb vim spec/unit/page_spec.rb 1 2

2.2 Setting up Docker Compose service

vim docker-compose.yml 3

2.3 Creating the Dockerfile

vim rspec.docerfile 4 vim docker-compose.yml 5

2.4 Running the test

docker-compose up -d website
docker-compose run -rm unit-tests 6 7

2.5 Identifying and testing an element

docker-compose config
docker-compose up -d website 8 9 vim page_spec.rb 10

2.6 Setting up Selenium

vim page_spec.rb
docker-compose run -rm unit-tests 11

2.7 Adding Selenium service to Docker Compose

vim docker-compose.yml 12 docker-compose up -d website selenium 13

2.8 Running the test with Selenium

docker-compose run --rm unit-tests 14

3. Infrastructure as code with Terraform

3.1 Creating the Terraform Dockerfile

vim terraform.Dockerfile 1 docker build -t terraform .
docker build -t terraform . -f terraform.Dockerfile
docker run --rm --interactive --tty --entrypoint sh terraform
2

3.2 Building and Testing a Terraform Docker image

docker build --tag terraform --file terraform.Dockerfile .
docker run --rm terraform
3

3.3 Creating a Terraform Docker Compose service

vim docker-compose.yml
docker-compose build terraform
docker-compose run --rm terraform
4 5 6

3.4 AWS deployment by writing Terraform code

vim main.tf 7

3.5 Reviewing and Applying Terraform plan

docker-compose run --rm terraform init
vim docker-compose.yml To add AWS access keys
docker-compose run --rm terraform plan
8 9 10

3.6 Deploying the website into AWS S3

docker-compose run --rm aws
docker-compose run --rm --entrypoint aws aws ec2 describe-instances
docker-compose run --rm --entrypoint aws aws s3 cp --recursive website/ s3://explorecalifornia.org
docker-compose run --rm terraform output
11 12 13

3.7 Writing integration test

vim page_spec.rb
docker-compose run --rm terraform plan
docker-compose run --rm terraform apply
vim docker-compose.yml
14 15 16 17

3.8 Running integration test

docker-compose up -d selenium
docker-compose run --rm integration-tests
docker-compose run --rm aws aws s3 cp website/ s3://explorecalifornia.org --recursive
docker-compose run --rm aws aws s3 r website/ s3://explorecalifornia.org --recursive
docker-compose run --rm terraform destroy
18 19 20 21 22

4. CI/CD as Code with Jenkins

4.1 Installing Jenkins on Docker

vim jenkins.Dockerfile
vim docker-compose.yml
docker-compose up jenkins
1 2 3 4 5

4.2 Writing a Jenkinsfile for the app

vim jenkinsfile 6

4.3 Using Jenkinsfile to deploy the app

git init
git checkout -b master
git add -A
git commit -m "Initialize repository"
docker-compose up jenkins
7 8 9 10 11 12 13

About

Accelerating Collaboration and Deployment with Docker, Terraform and Jenkins: DevOps Project for the Website 'Explore California'

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published