Skip to content

Commit

Permalink
feat: add deploying to digital ocean using ansible
Browse files Browse the repository at this point in the history
Signed-off-by: Brent Hoover <[email protected]>
Signed-off-by: rickyholland <[email protected]>
  • Loading branch information
brent-hoover authored and RickyHolland committed Feb 21, 2022
1 parent 3c4b98e commit 0e4fef9
Showing 1 changed file with 169 additions and 0 deletions.
169 changes: 169 additions & 0 deletions guides/deploying-to-digital-ocean-with-ansible.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
## At a Glance

This deployment guide's purpose is to provide a simple and easy guide on how to deploy Open Commerce for evaluation purposes or small deployments. This guide is not meant to generate an enterprise production grade deployment. This deployment guide does not use Kubernetes, instead, Docker Compose is used to manage containers.

> Note: It is important to understand that Open Commerce cannot provide support for your deployment. If you need
> help you can reach out to the community on our [Discord Server](https://discord.gg/Bwm63tBcQY)
## What you need

- A Linux host with at least 2GB of RAM, this guide uses a DigitalOcean droplet
- A registered domain
- A DNS manager that supports Certification Authority Authorization (CCA) records, such as Digital Ocean
- Docker
- Docker Compose
- Git
- Node
- Yarn
- Some familiarity with [Traefik](https://github.com/containous/traefik/)

## Open Commerce Services Overview

- Reaction GraphQL API
The [Reaction GraphQL API](https://github.com/reactioncommerce/reaction) service provides the interface to the Reaction core functionality.
- Storefront
The [example storefront](https://github.com/reactioncommerce/example-storefront) service provides the public facing storefront interface that customers will interact with.
- Reaction Admin
The [Reaction Admin](https://github.com/reactioncommerce/reaction-admin) service is a Meteor application that provides the admin UI to manage products, orders etc.

## Getting Started

Open Commerce services will be exposed to the public using [Traefik](https://github.com/containous/traefik/), which
is a cloud native router. Traefik will act as a reverse proxy that will route traffic to Docker containers. As stated above, you will need a registered domain to complete this step, as it will be necessary to manage DNS records for it.

This guide will use the following sub-domains, where `example.com` will need to substitute it with your domain:

| subdomain | description |
| ---------------------- |-----------------------------------|
| api.example.com | The open Commerce GraphQL API |
| storefront.example.com | The example storefront |
| admin.example.com | The Open Commerce admin interface |
| traefik.example.com | Traefik's admin UI |

Each of your domains will need an `A` DNS record that resolves to your host's IP. It's recommend to use DigitalOcean's free [DNS manager](https://www.digitalocean.com/docs/networking/dns/overview/). Further, in order to obtain SSL certificates for your sub-domains, you will need a DNS manager that supports [CAA](https://support.dnsimple.com/articles/caa-record/) records.


Further, you will need a [DigitalOcean Auth token](https://docs.digitalocean.com/reference/api/create-personal-access-token/) to generate CAA records for your sub-domains.

## Prepare the Remote Host

In this guide a DigitalOcean node will be used to host the Open Commerce Platform. If you don't yet have an account, create one at [digitalocean.com](https://digitalocean.com). Once you are signed into your account, create a new droplet using the Ubuntu 18.4 image with at least 2GB of RAM. Enable DigitalOcean's [free firewall](https://www.digitalocean.com/docs/networking/firewalls/) and add inbound rules for SSH, HTTP, HTTPS and add your droplet to the firewall.

After the droplet is created either select an existing SSH key to login or click on the "New SSH Key" under the authentication section and copy your public SSH key from your local computer.

Copy the newly created IP address and verify that you can login into the new server by executing:

```
ssh [email protected]
```

## Prepare the Control Node

Ansible requires a control node, which is a computer that manages a remote host. This guide assumes a Mac laptop/desktop as the control node.

Install Ansible using [homebrew](https://brew.sh), this guide assumes some familiarity with Ansible, if you need an introduction to basic concepts click [here](https://www.ansibletutorials.com).

`brew install ansible`

Also install python3 to avoid deprecation warnings,

`brew install python3`

###### Prepare the Control Node

Ansible requires a control node, which is a computer that manages a remote host. This guide will assumes a Mac laptop/desktop as the control node.

Install Ansible using [homebrew](https://brew.sh), this guide assumes some familiarity with Ansible, if you need an introduction to basic concepts click [here](https://www.ansibletutorials.com).

`brew install ansible`

Also install python3 to avoid deprecation warnings,

`brew install python3`

## Configure the remote host to be managed with Ansible

On the control node(i.e. a developer's machine) create an inventory file in which `python3` is specified as the interpreter. On your machine, create a new file at named `hosts` at `/etc/ansible`.

Create inventory file
```
touch /etc/ansible/hosts
```

Add the following content to the inventory file:
```
[servers]
reaction.server
[servers:vars]
ansible_python_interpreter=/usr/bin/python3
[web]
```

Edit your hosts file
```
sudo vim /etc/hosts
```

and add an entry for the DigitalOcean droplet,

```
XXX.XXX.XXX.XXX reaction.server
```

Verify that Ansible can communicate with your remote host by executing:

```
ansible all -m ping -u root
```

Your should see output similar to:

```
reaction.dev | SUCCESS => {
"changed": false,
"ping": "pong"
}
```

## Set Ansible Environment Variables

Before executing the Ansible playbook, it's necessary to set variables that are specific to your deployment. Find the
`vars` section in the `reaction.yml` playbook and update as necessary, below is a list of the variable
that need to be updated and a description of each.

| Variable | Description |
| ---------------------- | ----------------------------------------------------------------------------|
| do_auth_token | The Authentication token for the Digital Ocean API |
| email | An email address to receive SSl certificate notifications |
| domain | Your registered domain |

For the rest of the variables, the default values should be used, DO NOT change otherwise, the playbook might fail.

## Execute the playbook

Now it's time to execute the `reaction.yml` playbook, which automates most of the tedious server configuration tasks, execute the following command:

```
ansible-playbook playbooks/reaction.yml -l reaction.server
```

NOTE: the `-l reaction.server` limits the execution of the playbook to the `reaction.server` host.

## Create the Primary Shop

At this point the Open Commerce GraphQL API, Example Storefront, Admin should be accessible over the internet.

To create the primary shop login into the Reaction Admin at the following URL, first substitute the `example.com` with your actual domain:
```
https://admin.example.com
```

Upon navigating to the Admin interface, you will be presented with a login form, it will be necessary to create a user first, so click on the "Register" link and fill out the form. Once logged in, proceed to create a shop in the admin interface.

Further, the `GraphQL API` explorer will be available at `https://api.example.com/graphql`.

## Wrapping Up

You have now successfully deployed Open Commerce to Digital Ocean using Ansible. You can now tweak your installation
to meet your needs including substituting your custom images for the stock ones that Open Commerce provides

0 comments on commit 0e4fef9

Please sign in to comment.