Skip to content

Commit

Permalink
ansible added
Browse files Browse the repository at this point in the history
  • Loading branch information
grzanka committed Oct 6, 2023
1 parent d9fb62b commit 238419d
Show file tree
Hide file tree
Showing 5 changed files with 190 additions and 169 deletions.
172 changes: 6 additions & 166 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,169 +1,9 @@
# Deploy of the yaptide platform to the OpenStack cloud platform
# Deployment of the yaptide platform

## The aim
This page describes local and cloud deployment of the yaptide platform.
It is indended for developers and administrators who want to deploy the platform on their own infrastructure.

The aim of this project it to provide an automated deploy of the yaptide platform to the OpenStack cloud platform.
The deployment is managed by the ansible playbooks. In this project two major playbooks are used:
- `cloud_instance.yml` - for creating (and teardown) a cloud instance
- `site.yml` - for deploying the yaptide platform
Please note that the demo version of application is also deployed on the Github pages:

## Local deployment

1. Install requirements necesary for running the ansible playbooks:

```
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
```

In our projects we use `ansible` Python package. It uses SSH to connect to the remote machines.
As for now the `ansible` package does not work natively on Windows.
The only way to run it from Windows is to use the `WSL` (Windows Subsystem for Linux).

2. Deploy the yaptide platform on the local machine.

The simulator binaries are copied from S3 or other types of storage at the moment when remote docker containers are starting.
```bash
ansible-playbook site.yml -i environments/local
```

3. To remove the yaptide platform from the instance, run:

```bash
ansible-playbook site.yml -i environments/local -e mode=clean
```

## Instructions

1. Downloand the `openrc.sh` file from the OpenStack dashboard and source it. If it asks for a password, use the one from the dashboard.

```
. plgrid-ext-plggyaptide-openrc.sh
```

2. Install requirements necesary for running the ansible playbooks:

```
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
```

In our projects we use `ansible` Python package. It uses SSH to connect to the remote machines.
As for now the `ansible` package does not work natively on Windows.
The only way to run it from Windows is to use the `WSL` (Windows Subsystem for Linux).

3. Query the dynamic inventory:

```bash
ansible-inventory --graph
```

To print public IPs of all instances in the dynamic inventory:

```bash
ansible -m debug -a "var=hostvars[inventory_hostname].ansible_host" all
```

4. Create an instance on OpenStack cloud:

This step may take about 3-4 minutes, so be patient. Once it is completed, a machine named `yaptide` will be created on the OpenStack cloud.

```bash
ansible-playbook cloud_instance.yml
```

Once the instance is created, you can optionally run time consuming package upgrade task on it. This step may take about 10-15 minutes, so be patient.

```bash
ansible yaptide -m apt -a "update_cache=yes upgrade=dist" --become
ansible yaptide -m reboot --become
```

In case you have an existing snaphot image, you can use it to create an instance.
This will save you some time, as the image will be used instead of installing all the packages from scratch.

```bash
ansible-playbook cloud_instance.yml -e "image_name='Ubuntu 20.04 LTS Snapshot 20230404'"
```

To get larger flavor with more CPUs or RAM, use the following command:

```bash
ansible-playbook cloud_instance.yml -e "flavor_name='h2.large'"
```

You can combine both options:

```bash
ansible-playbook cloud_instance.yml -e "image_name='Ubuntu 22.04 LTS Snapshot (20230404)'" -e "flavor_name='h2.large'"
```


To create an instance with a different name, use the following command:

```bash
ansible-playbook cloud_instance.yml -e "instance_name='yaptide2'"
```

5. Deploy the yaptide platform on the instance.
At this stage necessary packages will be installed and respective repositories cloned.
The backend will be served on port 5000 and the frontend on port 80.
This step is time consuming and may take more than 10 minutes.

The simulator binaries are copied from S3 or other types of storage at the moment when remote docker containers are starting.

```bash
ansible-playbook site.yml
```

To perform deployment on a specific branch, use the following command:

```bash
ansible-playbook site.yml -e backend_repo_version='backend-branch-name' -e frontend_repo_version='frontend-branch-name'
```

To specify different IP of the backend and frontend:

```bash
ansible-playbook site.yml -e frontend_backend_hostname='149.156.182.181' -e frontend_ui_hostname='149.156.182.181' -e backend_repo_version='backend-branch-name' -e frontend_repo_version='frontend-branch-name'
```
or

```
ansible-playbook site.yml -e frontend_backend_hostname='yap-dev.c3.plgrid.pl' -e frontend_backend_url='https://yap-dev.c3.plgrid.pl:5000' -e frontend_ui_hostname='yap-dev.c3.plgrid.pl' -e frontend_ui_hostname='https://yap-dev.c3.plgrid.pl'
```

or

```
ansible-playbook site.yml -e @plgrid_vars.yml
```

You can also run only few stages of the deployment. For example to perform only installation of necessary packages, use the following command:

```bash
ansible-playbook site.yml --tags "setup"
```

To deploy on an instance with a different name, use the following command:

```bash
ansible-playbook site.yml -e "variable_host='yaptide2'"
```

Once the `yaptide` platform is deployed, you can access it by visiting the public IP of the instance in your browser.
The password to the admin account can be found in the file `roles/backend/files/password` in the repository.

6. To remove the yaptide platform from the instance, run:

```bash
ansible-playbook site.yml -e mode=clean
```

7. Tear down the instance.

```bash
ansible-playbook cloud_instance.yml -e mode=clean
```
* [production demo](https://yaptide.github.io/) (updated on every release of the frontend)
* [development demo](https://yaptide.github.io/web_dev/) (updated on every push to the `main` branch of the frontend repository)
169 changes: 169 additions & 0 deletions docs/ansible.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
# Deploy of the yaptide platform to the OpenStack cloud platform

## The aim

The aim of this project it to provide an automated deploy of the yaptide platform to the OpenStack cloud platform.
The deployment is managed by the ansible playbooks. In this project two major playbooks are used:
- `cloud_instance.yml` - for creating (and teardown) a cloud instance
- `site.yml` - for deploying the yaptide platform

## Local deployment

1. Install requirements necesary for running the ansible playbooks:

```
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
```

In our projects we use `ansible` Python package. It uses SSH to connect to the remote machines.
As for now the `ansible` package does not work natively on Windows.
The only way to run it from Windows is to use the `WSL` (Windows Subsystem for Linux).

2. Deploy the yaptide platform on the local machine.

The simulator binaries are copied from S3 or other types of storage at the moment when remote docker containers are starting.
```bash
ansible-playbook site.yml -i environments/local
```

3. To remove the yaptide platform from the instance, run:

```bash
ansible-playbook site.yml -i environments/local -e mode=clean
```

## Instructions

1. Downloand the `openrc.sh` file from the OpenStack dashboard and source it. If it asks for a password, use the one from the dashboard.

```
. plgrid-ext-plggyaptide-openrc.sh
```

2. Install requirements necesary for running the ansible playbooks:

```
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
```

In our projects we use `ansible` Python package. It uses SSH to connect to the remote machines.
As for now the `ansible` package does not work natively on Windows.
The only way to run it from Windows is to use the `WSL` (Windows Subsystem for Linux).

3. Query the dynamic inventory:

```bash
ansible-inventory --graph
```

To print public IPs of all instances in the dynamic inventory:

```bash
ansible -m debug -a "var=hostvars[inventory_hostname].ansible_host" all
```

4. Create an instance on OpenStack cloud:

This step may take about 3-4 minutes, so be patient. Once it is completed, a machine named `yaptide` will be created on the OpenStack cloud.

```bash
ansible-playbook cloud_instance.yml
```

Once the instance is created, you can optionally run time consuming package upgrade task on it. This step may take about 10-15 minutes, so be patient.

```bash
ansible yaptide -m apt -a "update_cache=yes upgrade=dist" --become
ansible yaptide -m reboot --become
```

In case you have an existing snaphot image, you can use it to create an instance.
This will save you some time, as the image will be used instead of installing all the packages from scratch.

```bash
ansible-playbook cloud_instance.yml -e "image_name='Ubuntu 20.04 LTS Snapshot 20230404'"
```

To get larger flavor with more CPUs or RAM, use the following command:

```bash
ansible-playbook cloud_instance.yml -e "flavor_name='h2.large'"
```

You can combine both options:

```bash
ansible-playbook cloud_instance.yml -e "image_name='Ubuntu 22.04 LTS Snapshot (20230404)'" -e "flavor_name='h2.large'"
```


To create an instance with a different name, use the following command:

```bash
ansible-playbook cloud_instance.yml -e "instance_name='yaptide2'"
```

5. Deploy the yaptide platform on the instance.
At this stage necessary packages will be installed and respective repositories cloned.
The backend will be served on port 5000 and the frontend on port 80.
This step is time consuming and may take more than 10 minutes.

The simulator binaries are copied from S3 or other types of storage at the moment when remote docker containers are starting.

```bash
ansible-playbook site.yml
```

To perform deployment on a specific branch, use the following command:

```bash
ansible-playbook site.yml -e backend_repo_version='backend-branch-name' -e frontend_repo_version='frontend-branch-name'
```

To specify different IP of the backend and frontend:

```bash
ansible-playbook site.yml -e frontend_backend_hostname='149.156.182.181' -e frontend_ui_hostname='149.156.182.181' -e backend_repo_version='backend-branch-name' -e frontend_repo_version='frontend-branch-name'
```
or

```
ansible-playbook site.yml -e frontend_backend_hostname='yap-dev.c3.plgrid.pl' -e frontend_backend_url='https://yap-dev.c3.plgrid.pl:5000' -e frontend_ui_hostname='yap-dev.c3.plgrid.pl' -e frontend_ui_hostname='https://yap-dev.c3.plgrid.pl'
```

or

```
ansible-playbook site.yml -e @plgrid_vars.yml
```

You can also run only few stages of the deployment. For example to perform only installation of necessary packages, use the following command:

```bash
ansible-playbook site.yml --tags "setup"
```

To deploy on an instance with a different name, use the following command:

```bash
ansible-playbook site.yml -e "variable_host='yaptide2'"
```

Once the `yaptide` platform is deployed, you can access it by visiting the public IP of the instance in your browser.
The password to the admin account can be found in the file `roles/backend/files/password` in the repository.

6. To remove the yaptide platform from the instance, run:

```bash
ansible-playbook site.yml -e mode=clean
```

7. Tear down the instance.

```bash
ansible-playbook cloud_instance.yml -e mode=clean
```
11 changes: 11 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Local deployment

## Requirements

To be able to run the application locally, you need to have following software installed:

* [Docker](https://docs.docker.com/get-docker/)
* [Docker Compose](https://docs.docker.com/compose/install/)
* [Git](https://git-scm.com/downloads)

Both products could be installed on Linux and Windows. Docker for Windows usually uses WSL2 (Windows Subsystem for Linux ) backend.
The commands listed below can be executed on plain Powershell, there is no need to run them inside WSL2.

## Prerequisites

First we need to clone both backend and frontend repositories:
Expand Down
5 changes: 3 additions & 2 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ site_url: https://yaptide.github.io/deploy/
repo_url: https://github.com/yaptide/deploy
repo_name: yaptide/deploy
copyright: Copyright © 2023 the Yaptide team

title: Deploy documentation

theme:
name: material
Expand All @@ -18,7 +18,8 @@ nav:
- Home:

Check warning on line 18 in mkdocs.yml

View workflow job for this annotation

GitHub Actions / linter (3.9)

yaml[indentation]

Wrong indentation: expected 2 but found 0

Check warning on line 18 in mkdocs.yml

View workflow job for this annotation

GitHub Actions / linter (3.10)

yaml[indentation]

Wrong indentation: expected 2 but found 0

Check warning on line 18 in mkdocs.yml

View workflow job for this annotation

GitHub Actions / linter (3.11)

yaml[indentation]

Wrong indentation: expected 2 but found 0
- Overview: index.md

Check warning on line 19 in mkdocs.yml

View workflow job for this annotation

GitHub Actions / linter (3.9)

yaml[indentation]

Wrong indentation: expected 4 but found 2

Check warning on line 19 in mkdocs.yml

View workflow job for this annotation

GitHub Actions / linter (3.10)

yaml[indentation]

Wrong indentation: expected 4 but found 2

Check warning on line 19 in mkdocs.yml

View workflow job for this annotation

GitHub Actions / linter (3.11)

yaml[indentation]

Wrong indentation: expected 4 but found 2
- Simulators: simulators.md
- Cloud deploy: ansible.md

plugins:
- search

Check warning on line 24 in mkdocs.yml

View workflow job for this annotation

GitHub Actions / linter (3.9)

yaml[indentation]

Wrong indentation: expected 2 but found 0

Check warning on line 24 in mkdocs.yml

View workflow job for this annotation

GitHub Actions / linter (3.10)

yaml[indentation]

Wrong indentation: expected 2 but found 0

Check warning on line 24 in mkdocs.yml

View workflow job for this annotation

GitHub Actions / linter (3.11)

yaml[indentation]

Wrong indentation: expected 2 but found 0
- section-index
- git-revision-date-localized
2 changes: 1 addition & 1 deletion requirements-docs.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
mkdocs==1.5.3
mkdocs-material==9.4.3
mkdocs-section-index==0.3.8
mkdocs-git-revision-date-localized-plugin==1.2.0

0 comments on commit 238419d

Please sign in to comment.