Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 93 additions & 6 deletions devops/01 - git/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,110 @@

* fork the current repository

Done

* after passing other test tasks (02 - dockerfile, 03 - docker-compose, 04 - bash, 05 - cloud-ops) need to squash all your commits to one

Done

* make a pull-request with the results of the tasks and tag Done-current date (e.g. `Done-01-01-2021`)


## Questions

1. What command can I use to view the commit history?

1. What command can I use to undo the last commit?
git log
<<<<<<< HEAD

2. What command can I use to undo the last commit?

git reset HEAD~1

3. What command can I use to create a new branch and a new tag?

git checkout -b NEWBRANCHNAME

git tag -a NEWTAG

4. How do I exclude a file / folder from a commit?

You should to add a name of this file/folder to file .gitignore or ./git/info/exclude

5. In case of a merge conflict, what commands can be used to resolve it?

git status

#to see which files are unmerged

git diff branch1..branch2

#to see difference between branches

git log branch1...branch2

#to see log/commit history after making branch

git reset HEAD

#to cancel merge, if it will be useful

git restore *

#to restore all files, if it will be useful

6. `*` What are pre-commit hooks and post-commit hooks, and what are they for?

pre-commit - checking the correctness of the data before commit.

post-commit - used to send notifications after commit.

7. `*` How do I change the last commit without adding a new commit?

=======

2. What command can I use to undo the last commit?

git reset HEAD^1

3. What command can I use to create a new branch and a new tag?

git checkout -b NEWBRANCHNAME

git tag -a NEWTAG

4. How do I exclude a file / folder from a commit?

You should to add a name of this file/folder to file .gitignore or ./git/info/exclude

5. In case of a merge conflict, what commands can be used to resolve it?

git status

#to see which files are unmerged

git diff branch1..branch2

#to see difference between branches

git log branch1...branch2

#to see log/commit history after making branch

git reset HEAD

#to cancel merge, if it will be useful

git restore *

#to restore all files, if it will be useful

1. What command can I use to create a new branch and a new tag?
6. `*` What are pre-commit hooks and post-commit hooks, and what are they for?

1. How do I exclude a file / folder from a commit?
pre-commit - checking the correctness of the data before commit.

1. In case of a merge conflict, what commands can be used to resolve it?
post-commit - used to send notifications after commit.

1. `*` What are pre-commit hooks and post-commit hooks, and what are they for?
7. `*` How do I change the last commit without adding a new commit?

1. `*` How do I change the last commit without adding a new commit?
git commit --amend
1 change: 0 additions & 1 deletion devops/02 - dockerfile/.env

This file was deleted.

8 changes: 6 additions & 2 deletions devops/02 - dockerfile/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
FROM golang:1.15
FROM golang:1.15 AS builder
WORKDIR /usr/src/app
RUN echo PORT=8888>./.env
COPY main.go .
COPY go.mod .
COPY .env .
RUN go get -d github.com/joho/godotenv
RUN CGO_ENABLED=0 GOOS=linux go build -o simple-webpage .

FROM scratch
WORKDIR /usr/src/app
COPY --from=builder /usr/src/app/simple-webpage /usr/src/app/.env ./
CMD ["./simple-webpage"]
34 changes: 34 additions & 0 deletions devops/02 - dockerfile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,52 @@ You need to optimize the Dockerfile by correcting or adding steps.

1. What is Docker? Which technology is it based on?

Docker is an application manager with container support. It is based on the LXC technology.

2. Look at the Docker file – what would you change in it?

I've added Multi-staging and creating .env file inside container.

3. How do I pass variables to the Docker file when building and running the container?

Through the .env file.

4. Why do we need multistage build ?

Because we don't need golang environment in a resulting image. One container - one application.

## Tasks

* Dockerfile - generate .env file inside Dockerfile, provide value of port at build step.

Done

* Multi-stage build – change the Dockerfile to make it multi-stage. Try to get the lowest container size.

6.7 MB

* Compare size of docker images with and without multistage build.

without multi-staging it was 858 MB, but with this one it became 6.7 MB

* Write down all commands which you have used.

cat .env

nano Dockerfile

docker pull golang:1.15

rm .env

docker build -t webcounter:1.0 .

docker run -d --name worker -p80:8888 webcounter:1.0

docker stop worker

nano README.md

git add .

git commit -m "02 - dockerfile"
61 changes: 51 additions & 10 deletions devops/03 - docker-compose/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,79 @@ Docker compose with 3 applications (frontend + backend + DB).

### Instructions for running

1. Bootstrap the DB:

`docker-compose up -d db`

`docker-compose run --rm flaskapp /bin/bash -c "cd /opt/services/flaskapp/src && python -c 'import database; database.init_db()'"`

2. Boot up the cluster
1. Bootstrap the DB and boot up the cluster

`docker-compose up -d`

3. Browse to localhost:8080 to see the app in action.
2. Browse to localhost:8080 to see the app in action.

## Questions

1. What is the difference between Docker Compose and dockerfile? Why do I need Docker Compose?

dockerfile is needed to describe how to build images, but docker compose is needed to describe how to run containers.

2. How do I parameterize compose for different environments?

create .env file with environment variables and use the vars from this file in docker-compose.yml file.

3. What types of entities are used in docker-compose and for what purpose?

version - version of docker-compose

services - services/applications to start in docker containers

db/flaskapp/nginx - containers names

image - docker images for services

volumes - volumes that storaged in docker outside containers for using inside containers

env_file - file in which described environment variables to export them inside container.

networks - networks in which container will have interface

depends_on - services which needed to be started before starting current service

command - command which will be executed after starting conatiner

ports - describing port translations

db_nw/web_nw - describing networks

driver - selecting driver for network interfaces in used network

4. `*` How to output application logs?

4. `*` How to copy\upload a file from host machine to the container?
sudo docker-compose logs SERVICE

5. `*` How to copy\upload a file from host machine to the container?

5. `*` How to save file changes made inside the container?
in Dockerfile: COPY /srcPath/srcFile ./dstPath

in dockercompose: volumes: - /srcPath/srcFile:/dstPath/dstFile

on run: docker cp /srcPath/srcFile containerName:/dstPath

6. `*` How to save file changes made inside the container?

we can use volume, upload file from container to host machine, use shared folder, save container to image


## Tasks

* Docker-compose has a bug - investigate it! What would you improve?

There is a little bug with NGINX config. Also I edited Dockerfile and docker-compose.yml
to build and run application with only "docker-compose up -d"
(but I added wait-for-it.sh script, recommended on docs.docker.com to make dependences between services and
execute commands on flaskapp to create DB after database start)

* Docker-compose with an environment file. Create 2 different environment files for docker-compose

I added environments to docker-compose file. Now it uses env_file and .env files.

* `*` Change the `docker-compose.yml` to run through dockerstack with code reuse (don't repeat yourself)

I edited docker-compose.yml, so now it can work with docker-compose and docker-stack (check this with
docker swarm with 1 host)
15 changes: 15 additions & 0 deletions devops/03 - docker-compose/example/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
DB_TAG=9.6.5
DB_VOLUME=dbdata
ENV_FILE=env_file
DB_NW=db_nw
WEB_NW=web_nw
FLASK_DOCKERFILE=.
DB_DIR=/var/lib/postgresql/data
FLASK_DIR=/opt/services/flaskapp/src
FLASK_PORT=5432
FLASK_CMD=bash -c "./wait-for-it.sh db:${FLASK_PORT} -- python -c 'import database; database.init_db()' && python app.py"
NGINX_TAG=1.13.5
PUB_PORT=8080
NGINX_PORT=80
SRC_CONFD=./conf.d
NGINX_CONFD=/etc/nginx/conf.d
2 changes: 0 additions & 2 deletions devops/03 - docker-compose/example/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@ RUN mkdir -p /opt/services/flaskapp/src
COPY requirements.txt /opt/services/flaskapp/src/
WORKDIR /opt/services/flaskapp/src
RUN pip install -r requirements.txt
COPY . /opt/services/flaskapp/src
EXPOSE 5090
CMD ["python", "app.py"]
3 changes: 1 addition & 2 deletions devops/03 - docker-compose/example/conf.d/flaskapp.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ server {
server_name localhost;

location / {
proxy_set_header Host $host;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;

proxy_pass http://flaskapp:5090;
}
Expand Down
45 changes: 26 additions & 19 deletions devops/03 - docker-compose/example/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,45 @@
version: '3'
services:
db:
image: "postgres:9.6.5"
image: "postgres:${DB_TAG:-9.6.5}"
ports:
- "5432:5432"
volumes:
- "dbdata:/var/lib/postgresql/data"
env_file:
- env_file
- "dbdata:${DB_DIR:-/var/lib/postgresql/data}"
env_file: &environ_file
- ${ENV_FILE:-env_file}
networks:
- db_nw
- ${DB_NW:-db_nw}
flaskapp:
build: .
env_file:
- env_file
build: ${FLASK_DOCKERFILE:-.}
image: "${FLASKAPP_IMAGE:-example_flaskapp}:latest"
env_file: *environ_file
ports:
- "5090:5090"
volumes:
- .:/opt/services/flaskapp/src
- .:${FLASK_DIR:-/opt/services/flaskapp/src}
networks:
- db_nw
- web_nw
- ${DB_NW:-db_nw}
- ${WEB_NW:-web_nw}
depends_on:
- db
command: ${FLASK_CMD:-bash -c "
./wait-for-it.sh db:5432 -- python -c 'import database; database.init_db()'
&& python app.py"
}
nginx:
image: "nginx:1.13.5"
image: "nginx:${NGINX_TAG:-1.13.5}"
ports:
- "8080:80"
- "${PUB_PORT:-8080}:${NGINX_PORT:-80}"
volumes:
- ./conf.d:/etc/nginx/conf.d
- ${SRC_CONFD:-./conf.d}:${NGINX_CONFD:-/etc/nginx/conf.d}
networks:
- web_nw
- ${WEB_NW:-web_nw}
depends_on:
- flaskapp
networks:
db_nw:
driver: bridge
web_nw:
driver: bridge
db_nw: &bridgedriver
driver: overlay
web_nw: *bridgedriver
volumes:
dbdata:
Loading