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
101 changes: 101 additions & 0 deletions Artyom_Serchenya/0/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.

# Every Vagrant development environment requires a box. You can search for
# boxes at https://vagrantcloud.com/search.
config.vm.box = "devops-test"

# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false

# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# NOTE: This will enable public access to the opened port
# config.vm.network "forwarded_port", guest: 80, host: 8080

# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine and only allow access
# via 127.0.0.1 to disable public access
# config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"

# Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network "private_network", ip: "192.168.33.10"

# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network "public_network"

# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder "../data", "/vagrant_data"

# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
# config.vm.provider "virtualbox" do |vb|
# # Display the VirtualBox GUI when booting the machine
# vb.gui = true
#
# # Customize the amount of memory on the VM:
# vb.memory = "1024"
# end
#
# View the documentation for the provider you are using for more
# information on available options.

# Enable provisioning with a shell script. Additional provisioners such as
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
# documentation for more information about their specific syntax and use.
config.vm.network :forwarded_port, guest: 80, host: 8080 # Apache HTTP
config.vm.network :forwarded_port, guest: 443, host: 8443 # Apache HTTPS
config.vm.network :forwarded_port, guest: 5000, host: 5000 # Flask debug server

config.vm.provision "shell", inline: <<-SHELL
apt-get update
apt-get install -y apache2
sudo su root
echo "ServerName loclhost:80" >> /etc/apache2/apache2.conf
sudo su vagrant
sudo ufw enable
sudo ufw allow 'Apache Full'
sudo ufw allow -y 'OpenSSH'
sudo apt-get install -y systemd
source /etc/apache2/envvars
apache2 -V
sudo mkdir /var/www/localhost
sudo chown -R $USER:$USER /var/www/localhost
sudo chmod -R 755 /var/www/localhost
sudo cp /vagrant/files/index.html /var/www/localhost/index.html
sudo cp /vagrant/files/localhost.conf /etc/apache2/sites-available/localhost.conf
sudo a2ensite localhost.conf
sudo a2dissite 000-default.conf
sudo apt-get install apache2 -y openssl
sudo a2enmod rewrite
sudo a2enmod ssl
sudo cp /vagrant/files/other/localhost.conf /etc/apache2/sites-available/localhost.conf
sudo /etc/init.d/apache2 restart
sudo apt-get install memcached
sudo cp /vagrant/files/per_minute /etc/cron.d/per_minute
sudo cp /vagrant/files/other/per_minute /var/spool/cron/per_minute

SHELL


end
8 changes: 8 additions & 0 deletions Artyom_Serchenya/0/files/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head>
<title>Welcome to localhost!</title>
</head>
<body>
<h1>Success! The localhost virtual host is working!</h1>
</body>
</html>
9 changes: 9 additions & 0 deletions Artyom_Serchenya/0/files/localhost.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName localhost
ServerAlias localhost
DocumentRoot /var/www/localhost
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
25 changes: 25 additions & 0 deletions Artyom_Serchenya/0/files/other/localhost.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName localhost
ServerAlias localhost
DocumentRoot /var/www/localhost
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</VirtualHost>

<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key

ServerAdmin webmaster@localhost
ServerName localhost
ServerAlias localhost
DocumentRoot /var/www/localhost
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
1 change: 1 addition & 0 deletions Artyom_Serchenya/0/files/other/per_minute
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* * * * * /home/vagrant/exercise-memcached.sh
2 changes: 2 additions & 0 deletions Artyom_Serchenya/0/files/per_minute
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* * * * * root /bin/sh /home/vagrant/exercise-memcached.sh

40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,43 @@ The mentor should be able to simply use your files, run `vagrant up`, and have y
> - It should additionally show the percentage of memcached memory used (From the API. Not the percentage of the OS memory.)
> - Don't worry about the look and style of the page. Just make it functional.
> - There is a basic python Flask app in /var/www/app you can use as a starting template


# HomeWork #1

## Setup

Download and install [minikube](https://kubernetes.io/docs/tasks/tools/install-minikube/) or setup kubernetes using [Docker Desktop](https://www.docker.com/products/docker-desktop).

## Summary
Probably all you heard about Nginx and Rambler story. Today you will try to implement stub page in support of Igor Sysoev

## Instructions

0. Get home task related files from folder `_hw#1`.
1. Learn the basics of how to use Minikube, configure and deploy kubernetes service with Nginx.
2. Install Nginx as [ingress controller](https://github.com/kubernetes/ingress-nginx). Nginx should be avialible on http://localhost:8080/
3. Configure Nginx to made it show stub page instead of default web page on custom date.
- Add to header "Powered by nginx"
- Add the HTML-file nginx-blackout folder somewhere to the server (e.g. /var/www/nginx-blackout/index.html)
Edit your root location in the nginx config to be like this:
```
location /nginx-blackout {
root /var/www;
break;
}

location / {
if ($time_iso8601 ~ ^2019-12-31T09:[0-2][0-9]:[0-9][0-9] ) {
return 302 /nginx-blackout;
}
# ... usual location config
}
```

4. Check that it works with the current date.
5. Prepare PR with your setup.

The mentor should be able to simply use your files, run `kubectl create -f yourfile.yaml`, and have your completed and fixed environment running for review.

### Optional task: made same config by using custom image for nginx
1 change: 0 additions & 1 deletion _hw#0/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.provision "file", source: "files/site.conf", destination: "/tmp/site.conf"
config.vm.provision "shell", path: "files/provision.sh"

# config.vm.synced_folder "#{ENV['HOME']}/devops-test-share", "/var/www/devops-test-share"

end
41 changes: 41 additions & 0 deletions _hw#1/files/nginx-blackout/blackout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<html>
<head>
<title>Добро пожаловать в Интернет без Nginx</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<style>body{background-color:#f7f7f7;margin:0;padding:0;font-family:'Segoe UI',Tahoma,sans-serif}.gr{color:#f7f7f7}#main-frame-error{width:600px;margin:100px auto}.icon{-webkit-user-select:none;display:inline-block;background-repeat:no-repeat;background-size:100%;height:72px;margin:0 0 40px;width:72px;content:-webkit-image-set(url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEgAAABIAQMAAABvIyEEAAAABlBMVEUAAABTU1OoaSf/AAAAAXRSTlMAQObYZgAAAENJREFUeF7tzbEJACEQRNGBLeAasBCza2lLEGx0CxFGG9hBMDDxRy/72O9FMnIFapGylsu1fgoBdkXfUHLrQgdfrlJN1BdYBjQQm3UAAAAASUVORK5CYII=) 1x,url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJAAAACQAQMAAADdiHD7AAAABlBMVEUAAABTU1OoaSf/AAAAAXRSTlMAQObYZgAAAFJJREFUeF7t0cENgDAMQ9FwYgxG6WjpaIzCCAxQxVggFuDiCvlLOeRdHR9yzjncHVoq3npu+wQUrUuJHylSTmBaespJyJQoObUeyxDQb3bEm5Au81c0pSCD8HYAAAAASUVORK5CYII=) 2x)}h1{color:#333;font-size:1.6em;font-weight:normal;line-height:1.25em;margin-bottom:16px}.error-code{color:#696969;display:inline-block;font-size:13px;margin-bottom:15px;opacity:.5;text-transform:uppercase}#main-message{margin-bottom:50px}#details-button{background:inherit;border:0;float:none;margin:0;padding:10px 0;text-decoration:underline;cursor:pointer;color:#696969;font-size:.875em;float:right}#details{color:#696969;margin:45px 0 50px}.hidden{display:none}#adr{font-weight:bold}#reload-button{-webkit-user-select:none;background:#4c8efa;border:0;border-radius:2px;box-sizing:border-box;color:#fff;cursor:pointer;float:left;font-size:.875em;margin:0;padding:10px 24px;transition:box-shadow 200ms cubic-bezier(0.4,0,0.2,1)}</style>
<style>
#main-frame-error {
max-width: 600px;
margin: 100px auto;
padding: 15px;
}
@media (max-width: 640px) {
.icon {
margin-bottom: 10px;
}
h1 {
font-size: 1.2em;
}
#main-message {
margin-bottom: 20px;
}
}
</style>
</head>
<body>
<div id="main-frame-error">
<div class="icon"></div>
<div id="main-message">
<h1>Добро пожаловать в Интернет без Nginx</h1>
<div class="error-code">IGOR_SYSOEV_ILLEGAL_SEARCH_AND_SEIZURE</div>
<div style="color: #696969;">Разработчик Nginx Игорь Сысоев был задержан по уголовному делу, сфабрикованному на основе безосновательной претензии Рамблера, пытающегося осуществить рейдерский захват Nginx. Без Nginx большинство сайтов в Интернете не смогут существовать, в том числе и этот.</div><br>
<div id="buttons">
<a href="https://habr.com/ru/post/480204/"><button id="reload-button">Подробнее</button></a>
</div>
<br/>
<br/>
<!-- https://github.com/podivilov/nginx-blackout/pull/6 -->
<!-- Yandex.Metrika counter --> <script type="text/javascript" > (function(m,e,t,r,i,k,a){m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)}; m[i].l=1*new Date();k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)}) (window, document, "script", "https://mc.yandex.ru/metrika/tag.js", "ym"); ym(56668441, "init", { clickmap:true, trackLinks:true, accurateTrackBounce:true, webvisor:true }); </script> <noscript><div><img src="https://mc.yandex.ru/watch/56668441" style="position:absolute; left:-9999px;" alt="" /></div></noscript> <!-- /Yandex.Metrika counter -->
</body>
</html>