-
Notifications
You must be signed in to change notification settings - Fork 0
DevOps
Docker, Docker Compose
RSpec, Capybara, Selenium
Terraform
Jenkins
Docker is a platform for running applications and their dependencies in isolated environments called containers, on nearly any operating system. Homebrew (brew.sh)for installing applications on Mac(Linux) Aptitude, YUM, and YaST are package managers that let you install anything on the Mac
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
$ brew install cask docker - cask(third-part repository) installs Docker, Docker CLI, Docker Compose
1.1.3. Install Docker on Windows
$ docker run hello-world
1.2. Dockerfile
The Dockerfile is a manifest that describes the image that the container will use when we run it. All of the configuration dependencies and environment dependencies and everything that the application needs will be expressed within the Dockerfile.
Docker will do a few things.
- The Docker reads and parses the Dockerfile.
- The Docker fetches the parent image that this image is going to use. If there is no parent image that you're going to use, you would start from scratch.
- The Docker runs any commands, within the Dockerfile that is on top of that image, lastly if defined you can set a process that runs whenever a container from that image is spun up.
1.2.1. Docker Hub is a repository of docker images.
The 'alpine' is the smallest version of the image
FROM nginx:alpine #parent image:tag
MAINTAINER Illya Korotun <illya.korotun@gmail.com> #author
COPY website /website #copy context into the image host directory to the container directory
COPY nginx.conf /etc/nginx/nginx.cong #copy the config file to the container
EXPLOSE 80 #we want to map one(80) of the ports on my Mac to the port on the container.
$ docker build --tag website . # create an image with tag/name "website" from "." (current directory)
$ docker run --publish 80:80 website # publish on ports HOST:Container
Docker compose is a simple and lightweight platform for running multiple container applications in a single stack and creating a network.
version: '3.7' # docker compose version
services:
website: # service name usually equals the container name
build: # looking for Dockerfile and build an image
context: . # Dockerfile address "."-current directory
ports: # container ports HOST:Container
- 80:80 # Dockerfile address "."-current directory
$ docker-compose run website
$ docker-compose up
$ docker-compose ps
$ docker ps
$ docker-compose down
- RSpec is a Ruby-based testing framework. RSpec is looking for a folder called Spes and
_spec.rbfiles (ex. page_spec.rb). - Capybara is a tool that lets you use a web driver to create a browser and interact with the website. It gets the HTML of a website, run Javascript, and tests things like a button looking like it should look.
- The web driver, which is what spins up the browser and runs tests against it.
- Rack Test is a very simple web browser that just renders HTML and tests it, but it can't do more complicated things like running Javascript or computing CSS.
- Selenium is a web driver that spins up a real web browser and tests against whatever the web browser sees, which is nice because our website does have computed CSS, and spinning up a real web browser and getting the results of that computed CSS.
$ mkdir spec
$ mkdir spec/unit
$ touch spec/unit/page_spec.rb
# spec/unit/page_spec.rb
require 'capybara'
require 'capybara/dsl'
describe "Ecample page render unit tests" do
it "Shold show the Explore California logo" do
end
end
2.1.3 Edit docker-compose adding the 'unit-test'
version: "3.7"
services:
website:
build:
context: .
ports:
- 80:80
unit-test: # new service
volumes: # mount the existing volume to the container
- "$PWD:/app" #current directory to /app
build: # build a new image
context: . #current context
dockerfile: rspec.dockerfile #spesific dockerfile
command:
- --pattern # entrypoint option
- /app/spec/unit/*_spec.rb # entrypoint option test target
$ touch rspec.dockerfile
# create from base ruby image
FROM ruby:alpine
MAINTAINER Illy Korotun <illya.korotun@gmail.com>
# apk is pacage from alpine
# add package ruby-nokogiri for parsing
RUN apk add build-base ruby-nokogiri
# install in contaimer from ruby gem library rubygems.org
RUN gem install rspec capybara selenium-webdriver
#Which process should start when container is starting
ENTRYPOINT ['rspec']
Two way say container how to run CMD and ENTRYPOINT
Every container start with the default comand #/bin/sh -c
CMD ['rspec'] # is mean #/bin/sh -c 'rspec'
ENTRYPOINT is running the command where it placed
ENTRYPOINT ['option1', 'option2'] # is mean docker run this_image --option1 --option2
ENTRYPOINT ['rspec'] # is mean docker run this_image rspec
docker-compose up -d website
docker-compose run --rm unit-test
The dot '.' should be shown as result of the successful test