Skip to content

Commit

Permalink
Improve docs with latest changes (#134)
Browse files Browse the repository at this point in the history
* Add varios scripts to improve ansible workflow

* Fix text

* Fix var

* Update settings

* Changed references of 0.0.x to master

* Start docker containers on reboot (#128)

* Changed script to down and timeout only for one second, added restart always

* Added tool terraform-do-uashield (#122)

* added tool terraform-do-uashield

* added readme

* Changed script to restart always and don't wait too much on docker compose down

Co-authored-by: Roman Demachkovych <[email protected]>
Co-authored-by: adam <[email protected]>

* Create README.MD

Co-authored-by: Denys Butenko <[email protected]>
Co-authored-by: vtinkerer <[email protected]>
Co-authored-by: rdemachkovych <[email protected]>
Co-authored-by: Roman Demachkovych <[email protected]>
  • Loading branch information
5 people authored Mar 6, 2022
1 parent 4b0184b commit d5d1389
Show file tree
Hide file tree
Showing 23 changed files with 256 additions and 24 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ COPY tsconfig.headless.json ./tsconfig.json

RUN yarn build:headless


# Optimizes the build, so no NODE_MODULES included in image. Don't remove this
FROM node:16.9.0-alpine

WORKDIR /code
Expand Down
4 changes: 2 additions & 2 deletions README-en.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Targets being attacked are changed automatically and are downloaded from the con
Or use [pre-built image](https://github.com/opengs/uashield/pkgs/container/uashield):

```bash
docker run -d ghcr.io/opengs/uashield:0.0.x 512 true
docker run -d ghcr.io/opengs/uashield:master 512 true
```

## Docker-compose version
Expand All @@ -67,7 +67,7 @@ docker run -d ghcr.io/opengs/uashield:0.0.x 512 true

## Deploy with Play With Docker - free instance for 4 hours

[![Try in PWD](https://raw.githubusercontent.com/play-with-docker/stacks/master/assets/images/button.png)](https://labs.play-with-docker.com/?stack=https://raw.githubusercontent.com/opengs/uashield/0.0.x/pwd-docker-compose.yml)
[![Try in PWD](https://raw.githubusercontent.com/play-with-docker/stacks/master/assets/images/button.png)](https://labs.play-with-docker.com/?stack=https://raw.githubusercontent.com/opengs/uashield/master/pwd-docker-compose.yml)

## Donations
Donations will be used to fund our operations:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
Або за допомогою вже [зібраного імежду](https://github.com/opengs/uashield/pkgs/container/uashield):

```bash
docker run -d ghcr.io/opengs/uashield:0.0.x 512 true
docker run -d ghcr.io/opengs/uashield:master 512 true
```

## Docker-compose версія
Expand All @@ -67,7 +67,7 @@ docker run -d ghcr.io/opengs/uashield:0.0.x 512 true

## Деплой на Play With Docker - безкоштовний інстанс на 4 години

[![Try in PWD](https://raw.githubusercontent.com/play-with-docker/stacks/master/assets/images/button.png)](https://labs.play-with-docker.com/?stack=https://raw.githubusercontent.com/opengs/uashield/0.0.x/pwd-docker-compose.yml)
[![Try in PWD](https://raw.githubusercontent.com/play-with-docker/stacks/master/assets/images/button.png)](https://labs.play-with-docker.com/?stack=https://raw.githubusercontent.com/opengs/uashield/master/pwd-docker-compose.yml)

## Пожертвування
Пожертвування будуть використовуватися виключно для цілей програми:
Expand Down
6 changes: 3 additions & 3 deletions pwd-docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
version: '3'
services:
uashield:
image: ghcr.io/opengs/uashield:0.0.x
image: ghcr.io/opengs/uashield:master
restart: always
environment:
WORKERS: '512'
WORKERS: '256'
USEPROXY: 'false'
deploy:
replicas: 6
replicas: 3

7 changes: 7 additions & 0 deletions tools/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# COMMUNITY CREATED

Fortunately or unfortunately these tools are created by community.

They can be not up to date, but we are trying our best.

If you see any issue - make an issue or contact us via Discord.
8 changes: 8 additions & 0 deletions tools/ansible/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ Optional step, can be skipped

ansible-playbook -u root stats.yaml -i hosts

### 8. Update to the latest version and restart containers

ansible-playbook -u root update.yaml -i hosts

## UA
### 1. Інсталюйте ansible на свою машину
#### Mac OS
Expand Down Expand Up @@ -97,3 +101,7 @@ ssh-agent bash -c "ssh-add /path/to/keys/*.pem"
### 7. Перевірка статистики успішних запитів

ansible-playbook -u root stats.yaml -i hosts

### 8. Оновити до останньої версії та перезавантажити

ansible-playbook -u root update.yaml -i hosts
5 changes: 5 additions & 0 deletions tools/ansible/ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[defaults]
deprecation_warnings=False
host_key_checking=False
strategy=linear ; default
; strategy=free ; do not wait for complete all hosts
18 changes: 18 additions & 0 deletions tools/ansible/create-vm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
# Usage example
# ./create-vm.sh eastus2

# Variables
INPUT=$1
LOCATION="${INPUT:-'norwayeast'}"
RESOURCE_GROUP='STOPWAR'
USER='azureuser'
IMAGE='UbuntuLTS'
for i in {1..4}
do
NAME=uashield-$LOCATION-unit-$i
echo "$NAME : Initializing vm..."
az vm create --admin-user=$USER --location=$LOCATION --name $NAME --resource-group $RESOURCE_GROUP --image $IMAGE --generate-ssh-keys
done

bash ./update-hosts.sh
4 changes: 2 additions & 2 deletions tools/ansible/roles/stats/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
- name: Get stats
shell: echo $(docker logs uashield | grep '| 200' -c)
shell: echo $(docker ps -q | xargs -L 1 docker logs | grep '| 200' -c)
register: echo_content

- debug:
msg: "Hits {{ echo_content.stdout }} requests."
msg: "Hit {{ echo_content.stdout }} requests."
44 changes: 33 additions & 11 deletions tools/ansible/roles/uashield/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,52 @@
---
- name: Clone uashield repo
- name: Check if repo is exist
stat:
path: "{{uashield_work_dir}}"
failed_when: false
changed_when: false
register: check_uashield_repo

- name: Clone repo
git:
repo: "{{uashield_git_url}}"
dest: "{{uashield_work_dir}}"
accept_hostkey: true
force: true
version: "master"
when: not check_uashield_repo.stat.exists

- name: Stop all containers
shell: "docker-compose down"
- name: Pull Latest Changes
shell: "git pull"
args:
chdir: "{{uashield_work_dir}}"
when: check_uashield_repo.stat.exists

- name: Get Running Docker Containers
shell: "docker ps -aq"
register: docker_info

- name: Stop Running Docker Containers
shell: "docker stop $(docker ps -aq)"
when: docker_info.stdout

- name: Remove Docker Containers
shell: "docker rm $(docker ps -aq)"
when: docker_info.stdout

- name: Remove old uashield images
- name: Remove Old Docker Image
shell: "docker rmi -f uashield"

- name: Run uashield
shell: "docker-compose up -d"
- name: Build Docker Image
shell: "docker build . -t uashield"
args:
chdir: "{{uashield_work_dir}}"

- name: Check docker started
shell: "docker ps"
args:
chdir: "{{uashield_work_dir}}"
- name: Run Instance
shell: "docker run -d uashield {{ uashield_threads }} {{ uashield_proxy }}"

- name: Check Docker is started
command: "docker ps"
register: output

- ansible.builtin.debug:
var: output
var: output.stdout_lines
2 changes: 2 additions & 0 deletions tools/ansible/stats.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---
- hosts: servers
strategy: linear
gather_facts: no
become: yes
become_user: root
vars_files:
Expand Down
14 changes: 14 additions & 0 deletions tools/ansible/update-hosts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

PUBLIC_IP_ADDRESSES="$(az vm list-ip-addresses --query '[*].virtualMachine.network.publicIpAddresses[0].ipAddress' | sed '1d;$d' | cut -d'"' -f2)"
for IP in $PUBLIC_IP_ADDRESSES
do
EXIST="$(cat hosts | awk '{print $1}' | grep $IP)"
if [ "$EXIST" == "$IP" ]
then
echo "[Skipping] $IP already exist"
else
echo $IP >> hosts
echo "[Changed] $IP is added to hosts"
fi
done
10 changes: 10 additions & 0 deletions tools/ansible/update.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- hosts: servers
become: yes
become_user: root
vars_files:
- vars/vars.yaml
roles:
- uashield
handlers:
- include: handlers/main.yml
2 changes: 2 additions & 0 deletions tools/ansible/vars/vars.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ docker_pip_executable: pip3

uashield_git_url: "https://github.com/opengs/uashield"
uashield_work_dir: /root/uashield/
uashield_threads: 2500
uashield_proxy: true
2 changes: 1 addition & 1 deletion tools/azure/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ PLEASE SHARE WITH YOUR FRIENDS AND ANYONE WHO WANTS TO HELP BUT DOESN&#39;T KNOW
![](https://github.com/opengs/uashield/blob/master/tools/azure/images/7.jpg)
![](https://github.com/opengs/uashield/blob/master/tools/azure/images/8.jpg)

8. Go to &quot;Advanced&quot; tab (above) and paste the script [https://github.com/opengs/uashield/blob/0.0.x/tools/azure/azure-custom-data-script.sh](https://github.com/opengs/uashield/blob/0.0.x/tools/azure/azure-custom-data-script.sh) (just copy it as a text) to &quot;Custom data&quot;.
8. Go to &quot;Advanced&quot; tab (above) and paste the script [https://github.com/opengs/uashield/blob/master/tools/azure/azure-custom-data-script.sh](https://github.com/opengs/uashield/blob/master/tools/azure/azure-custom-data-script.sh) (just copy it as a text) to &quot;Custom data&quot;.
![](https://github.com/opengs/uashield/blob/master/tools/azure/images/9.jpg)
9. Go to &quot;Disk&quot; tab and change &quot;OS disk type&quot; from &quot;Premium SSD&quot; to &quot;Standart SSD&quot;.
![](https://github.com/opengs/uashield/blob/master/tools/azure/images/10.jpg)
Expand Down
6 changes: 5 additions & 1 deletion tools/azure/azure-custom-data-script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ version: \"3.3\"
services:
worker:
image: ghcr.io/opengs/uashield:latest
restart: always
command:
- \"7500\"
- \"true\"" >> /home/docker-compose.yaml
Expand All @@ -32,5 +33,8 @@ cd /home/

sudo docker-compose pull && sudo docker-compose up -d --scale worker=$(grep -c ^processor /proc/cpuinfo)

sudo echo "*/30 * * * * cd /home/ && sudo docker-compose down && sudo docker-compose pull && sudo docker-compose up -d --scale worker=$(grep -c ^processor /proc/cpuinfo)" >> /home/cronjob
sudo echo "*/30 * * * * cd /home/ && sudo docker-compose down -t 1 && sudo docker-compose pull && sudo docker-compose up -d --scale worker=$(grep -c ^processor /proc/cpuinfo)" >> /home/cronjob

# restart:always should do the job to run container on startup, but the hard restart is good here to avoid problems
sudo echo "@reboot cd /home/ && sudo docker-compose down -t 1 && sudo docker-compose pull && sudo docker-compose up -d --scale worker=$(grep -c ^processor /proc/cpuinfo)" >> /home/cronjob
crontab /home/cronjob
2 changes: 1 addition & 1 deletion tools/helm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ helm upgrade --install \
| fullnameOverride | string | `""` | |
| image.pullPolicy | string | `"IfNotPresent"` | |
| image.repository | string | `"ghcr.io/opengs/uashield"` | |
| image.tag | string | `"0.0.x"` | |
| image.tag | string | `"master"` | |
| imagePullSecrets | list | `[]` | |
| nameOverride | string | `""` | |
| nodeSelector | object | `{}` | |
Expand Down
2 changes: 1 addition & 1 deletion tools/helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ image:
repository: ghcr.io/opengs/uashield
pullPolicy: IfNotPresent
# We can find a tag here: https://github.com/opengs/uashield/pkgs/container/uashield
tag: "0.0.x"
tag: "master"

resources:
# We usually recommend not to specify default resources and to leave this as a conscious
Expand Down
36 changes: 36 additions & 0 deletions tools/terraform-do-uashield/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[![DigitalOcean Referral Badge](https://web-platforms.sfo2.cdn.digitaloceanspaces.com/WWW/Badge%201.svg)](https://www.digitalocean.com/?refcode=4e29ef6429c9&utm_campaign=Referral_Invite&utm_medium=Referral_Program&utm_source=badge)

[Get $100 to try DigitalOcean, link for sing in above](https://try.digitalocean.com/freetrialoffer/)


## Requirements
- [Instal terraform](https://www.terraform.io/downloads)
- [Add SSH key](https://docs.digitalocean.com/products/droplets/how-to/add-ssh-keys/to-account/) to DO with name `ssh`


## Export environment vars
Extra logs
```
export TF_LOG=INFO
```
## Create and export DO PAT
- [DO PAT](https://docs.digitalocean.com/reference/api/create-personal-access-token/)
```
export DO_PAT="<your_pat>"
```
## Init terraform
```
terraform init
```

```
terraform apply \
-var "do_token=${DO_PAT}" \
-var "pvt_key=$HOME/.ssh/id_ed25519"
```

```
terraform destroy \
-var "do_token=${DO_PAT}" \
-var "pvt_key=$HOME/.ssh/id_ed25519"
```
16 changes: 16 additions & 0 deletions tools/terraform-do-uashield/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
terraform {
required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = "~> 2.0"
}
}
}

provider "digitalocean" {
token = var.do_token
}

data "digitalocean_ssh_key" "ssh" {
name = "drvdo"
}
39 changes: 39 additions & 0 deletions tools/terraform-do-uashield/scripts/uashield.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/sh

sudo apt-get install -y \
ca-certificates \
curl \
gnupg \
lsb-release \
wget

curl -sSL https://repos.insights.digitalocean.com/install.sh | sudo bash

wget -O - https://get.docker.com/ | bash

sudo systemctl enable docker.service
sudo systemctl start docker.service

mkdir -p ~/.docker/cli-plugins/
curl -SL https://github.com/docker/compose/releases/download/v2.2.3/docker-compose-linux-x86_64 -o ~/.docker/cli-plugins/docker-compose
chmod +x ~/.docker/cli-plugins/docker-compose
sudo chown $USER /var/run/docker.sock

sudo echo "
version: \"3.3\"
services:
worker:
image: ghcr.io/opengs/uashield:latest
restart: always
command:
- \"7500\"
- \"true\"" >> /home/docker-compose.yaml

sudo apt install -y docker-compose

cd /home/

sudo docker-compose pull && sudo docker-compose up -d --scale worker=$(grep -c ^processor /proc/cpuinfo)

sudo echo "*/30 * * * * cd /home/ && sudo docker-compose down -t 1 && sudo docker-compose pull && sudo docker-compose up -d --scale worker=$(grep -c ^processor /proc/cpuinfo)" >> /home/cronjob
crontab /home/cronjob
33 changes: 33 additions & 0 deletions tools/terraform-do-uashield/uashield.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
resource "digitalocean_droplet" "uashield" {
count = var.droplet_instance_number
image = "ubuntu-20-04-x64"
name = "uashield-${count.index}"
region = "nyc3"
size = var.droplet_instance_size
monitoring = true

ssh_keys = [
data.digitalocean_ssh_key.ssh.id
]

connection {
host = self.ipv4_address
user = "root"
type = "ssh"
private_key = file(var.pvt_key)
timeout = "2m"
}

provisioner "file" {
source = "scripts/uashield.sh"
destination = "/opt/uashield.sh"
}

provisioner "remote-exec" {
inline = [
"chmod +x /opt/uashield.sh",
"/opt/uashield.sh",
]
}
}

Loading

0 comments on commit d5d1389

Please sign in to comment.