├── LICENSE ├── README.md ├── docs └── img │ ├── reaction_deployment_diagram.svg │ └── splash.png ├── example-storefront └── docker-compose.override.yml ├── playbooks └── reaction.yml ├── portainer └── docker-compose.yml ├── reaction-admin └── docker-compose.override.yml ├── reaction └── docker-compose.override.yml └── traefik ├── acme.json ├── docker-compose.yml └── traefik.yml /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2018 Reaction Commerce 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Deploy the Reaction Platform on Digital Ocean 2 | 3 | ### Overview 4 | 5 | This deployment guide's purpose is to provide a simple and easy guide on how to deploy the Reaction platform 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. 6 | 7 | ## Table of Contents 8 | - [Requirements](#requirements) 9 | - [Reaction Services Overview](#reaction-platform-services-overview) 10 | - [Getting Started](#getting-started) 11 | - [Automated Server Configuration](#automated-server-configuration) 12 | - [Prepare the Remote Host](#prepare-the-remote-host) 13 | - [Prepare the Control Node](#prepare-the-control-node) 14 | - [Configure the remote host to be managed with Ansible](#configure-the-remote-host-to-be-managed-with-ansible) 15 | - [Generate a secure password for HTTP Basic Auth](#generate-a-secure-password-for-http-basic-auth) 16 | - [Set Ansible Environment Variables](#set-ansible-environment-variables) 17 | - [Execute the Playbook](#execute-the-playbook) 18 | - [Create the Primary Shop](#create-the-primary-shop) 19 | - [Video Tutorial](#video-tutorial) 20 | - [Command Cheatsheet](#command-cheatsheet) 21 | 22 | ### Requirements 23 | 24 | - A Linux host with at least 2GB of RAM, this guide uses a DigitalOcean droplet 25 | - A registered domain 26 | - A DNS manager that supports Certification Authority Authorization (CCA) records, such as Digital Ocean 27 | - Docker 28 | - Docker Compose 29 | - Git 30 | - Node 31 | - Yarn 32 | - Some familiarity with [Traefik](https://github.com/containous/traefik/) 33 | 34 | ### Reaction Platform Services Overview 35 | 36 | ###### Reaction GraphQL API 37 | The [Reaction GraphQL API](https://github.com/reactioncommerce/reaction) service provides the interface to the Reaction core functionality. 38 | 39 | ###### Storefront 40 | The [example storefront](https://github.com/reactioncommerce/example-storefront) service provides the public facing storefront interface that customers will interact with. 41 | 42 | ###### Reaction Admin 43 | The [Reaction Admin](https://github.com/reactioncommerce/reaction-admin) service is a Meteor(currently being migrated off Meteor) application that provides the admin UI to manage products, orders etc. 44 | 45 | 46 | ## Getting Started 47 | 48 | Reaction 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. 49 | 50 | This guide will use the following sub-domains, where `example.com` will need to be substitute it with your domain: 51 | 52 | | subdomain | description | 53 | | ---------------------- | ------------------------------------- | 54 | | api.example.com | The Reaction GraphQL API | 55 | | storefront.example.com | The example storefront | 56 | | admin.example.com | The Reaction admin interface | 57 | | traefik.example.com | Traefik's admin UI | 58 | 59 | 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. 60 | 61 | 62 | 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. 63 | 64 | 65 | # Automated Server Configuration 66 | 67 | In order to expedite the installation of server dependencies, Ansible will be used to automate most of the server configuration. 68 | 69 | ###### Prepare the Remote Host 70 | 71 | In this guide a DigitalOcean node will be used to host the Reaction 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. 72 | 73 | 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. 74 | 75 | Copy the newly created IP address and verify that you can login into the new server by executing: 76 | 77 | ``` 78 | ssh root@XXX.XXX.XXX.XXX 79 | ``` 80 | 81 | ###### Prepare the Control Node 82 | 83 | 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. 84 | 85 | 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). 86 | 87 | `brew install ansible` 88 | 89 | Also install python3 to avoid deprecation warnings, 90 | 91 | `brew install python3` 92 | 93 | ###### Configure the remote host to be managed with Ansible 94 | 95 | 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`. 96 | 97 | Create inventory file 98 | ``` 99 | touch /etc/ansible/hosts 100 | ``` 101 | 102 | Add the following content to the inventory file: 103 | ``` 104 | [servers] 105 | reaction.server 106 | 107 | [servers:vars] 108 | ansible_python_interpreter=/usr/bin/python3 109 | [web] 110 | ``` 111 | 112 | Edit your hosts file 113 | ``` 114 | sudo vim /etc/hosts 115 | ``` 116 | 117 | and add an entry for the DigitalOcean droplet, 118 | 119 | ``` 120 | XXX.XXX.XXX.XXX reaction.server 121 | ``` 122 | 123 | Verify that Ansible can communicate with your remote host by executing: 124 | 125 | ``` 126 | ansible all -m ping -u root 127 | ``` 128 | 129 | Your should see output similar to: 130 | 131 | ``` 132 | reaction.dev | SUCCESS => { 133 | "changed": false, 134 | "ping": "pong" 135 | } 136 | ``` 137 | 138 | ###### Set Ansible Environment Variables 139 | 140 | Before executing the Ansible playbook, it's necessary to set variables that are specific to your deployment. Find the 141 | `vars` section in the `reaction.yml` playbook and update as necessary, below is a list of the variable 142 | that need to be updated and a description of each. 143 | 144 | | Variable | Description | 145 | | ---------------------- | ----------------------------------------------------------------------------| 146 | | do_auth_token | The Authentication token for the Digital Ocean API | 147 | | email | An email address to receive SSl certificate notifications | 148 | | domain | Your registered domain | 149 | 150 | For the rest of the variables, the default values should be used, DO NOT change otherwise, the playbook might fail. 151 | 152 | ###### Execute the playbook 153 | 154 | Now it's time to execute the `reaction.yml` playbook, which automates most of the tedious server configuration tasks, execute the following command: 155 | 156 | ``` 157 | ansible-playbook playbooks/reaction.yml -l reaction.server 158 | ``` 159 | 160 | NOTE: the `-l reaction.server` limits the execution of the playbook to the `reaction.server` host. 161 | 162 | ###### Create the Primary Shop 163 | 164 | At this point the Reaction GraphQL API, Example Storefront, Reaction Admin, Reaction Identity and Hydra should be accessible over the internet. 165 | 166 | To create the primary shop login into the Reaction Admin at the following URL, first substitute the `example.com` with your actual domain: 167 | ``` 168 | https://admin.example.com 169 | ``` 170 | 171 | Upon navigating to the Reaction 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. 172 | 173 | Further, the `GraphQL API` explorer will be available at `https://api.example.com/graphql`. 174 | 175 | ### Video Tutorial 176 | 177 | [![Deploy the Reaction Platform on DigitalOcean](docs/img/splash.png)](http://www.youtube.com/watch?v=7g5LfEVLt1U "Deploy the Reaction Platform on DigitalOcean") 178 | 179 | ### Command Cheatsheet 180 | 181 | The following bash aliases are automatically added to the remote server for convenience. 182 | 183 | ``` 184 | # Docker Compose 185 | alias dc='docker-compose' 186 | 187 | # Bring all services down 188 | alias dcd='docker-compose down' 189 | 190 | # Attach to all logs of all services 191 | alias dcl='docker-compose logs -f' 192 | 193 | # Run a comand inside a running container 194 | alias dcr='docker-compose run --rm' 195 | 196 | # "Restart" all services 197 | alias dcre='docker-compose down && docker-compose up -d && docker-compose logs -f' 198 | 199 | # Bring all services up in daemon mode 200 | alias dcu='docker-compose up -d' 201 | 202 | # Bring all containers up and attach to their logs 203 | alias dcul='docker-compose up -d && docker-compose logs -f' 204 | 205 | # Remove exited containers 206 | alias dprune='docker ps -aq --no-trunc -f status=exited | xargs docker rm' 207 | 208 | # Show all running containers, with horizontal paging 209 | alias dps='docker ps -a | less -S' 210 | ``` 211 | -------------------------------------------------------------------------------- /docs/img/reaction_deployment_diagram.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/img/splash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reactioncommerce/proxy-traefik/dd287533fc7bcd897813cc0b840fd1467ef6bcad/docs/img/splash.png -------------------------------------------------------------------------------- /example-storefront/docker-compose.override.yml: -------------------------------------------------------------------------------- 1 | version: '3.4' 2 | 3 | networks: 4 | web: 5 | external: 6 | name: web 7 | services: 8 | web: 9 | labels: 10 | - "traefik.enable=true" 11 | - "traefik.http.routers.web.entrypoints=http" 12 | - "traefik.http.routers.web.rule=Host(`storefront.example.com`)" 13 | - "traefik.http.middlewares.web-https-redirect.redirectscheme.scheme=https" 14 | - "traefik.http.routers.web.middlewares=web-https-redirect" 15 | - "traefik.http.routers.web-secure.entrypoints=https" 16 | - "traefik.http.routers.web-secure.rule=Host(`storefront.example.com`)" 17 | - "traefik.http.routers.web-secure.tls=true" 18 | - "traefik.http.routers.web-secure.service=web" 19 | - "traefik.http.services.web.loadbalancer.server.port=4000" 20 | - "traefik.docker.network=web" 21 | 22 | networks: 23 | web: 24 | -------------------------------------------------------------------------------- /playbooks/reaction.yml: -------------------------------------------------------------------------------- 1 | ########################################################################################################### 2 | # Playbook: Initial Server Setup for the Reaction Platform on a Ubuntu 18.4 Digital Ocean Droplet. 3 | # This playbook will also configure and docker-compose based deployment of the Reaction platform. 4 | ################################################################################################################### 5 | 6 | --- 7 | - hosts: all 8 | remote_user: root 9 | gather_facts: true 10 | vars: 11 | do_auth_token: "YOUR_DIGITALOCEAN_AUTH_TOKEN" 12 | domain: "YOUR_DOMAIN" 13 | email: "YOUR_EMAIL" 14 | 15 | create_user: reaction 16 | copy_local_key: "{{ lookup('file', lookup('env','HOME') + '/.ssh/id_rsa.pub') }}" 17 | docker_compose_version: "1.25.4" 18 | nodejs_version: "12.x" 19 | proxy_dir: proxy 20 | proxy_path: "/home/{{ create_user }}/{{ proxy_dir }}" 21 | reaction_dir: reaction-development-platform 22 | reaction_platform_path: "/home/{{create_user}}/{{reaction_dir}}" 23 | traefik_admin_user: reaction 24 | traefik_path: "/home/{{ create_user }}/{{ proxy_dir }}/traefik" 25 | 26 | tasks: 27 | - name: Make sure we have a 'wheel' group 28 | group: 29 | name: wheel 30 | state: present 31 | 32 | - name: Make sure we have a 'docker' group to facilitate running docker without sudo. 33 | group: 34 | name: docker 35 | state: present 36 | 37 | - name: Allow 'wheel' group to have password-less sudo 38 | lineinfile: 39 | path: /etc/sudoers 40 | state: present 41 | regexp: "^%wheel" 42 | line: "%wheel ALL=(ALL) NOPASSWD: ALL" 43 | validate: "/usr/sbin/visudo -cf %s" 44 | 45 | - name: Create a new regular user with sudo privileges 46 | user: 47 | name: "{{ create_user }}" 48 | state: present 49 | groups: wheel, docker 50 | append: true 51 | create_home: true 52 | shell: /bin/bash 53 | 54 | - name: Set authorized key for remote user 55 | authorized_key: 56 | user: "{{ create_user }}" 57 | state: present 58 | key: "{{ copy_local_key }}" 59 | 60 | - name: Disable password authentication for root 61 | lineinfile: 62 | path: /etc/ssh/sshd_config 63 | state: present 64 | regexp: "^#?PermitRootLogin" 65 | line: "PermitRootLogin prohibit-password" 66 | 67 | - name: Update apt 68 | apt: update_cache=yes 69 | 70 | - name: Install aptitude using apt 71 | apt: name=aptitude state=latest update_cache=yes force_apt_get=yes 72 | 73 | - name: Install required system packages 74 | apt: name={{ item }} state=latest update_cache=yes 75 | loop: 76 | [ 77 | "apt-transport-https", 78 | "build-essential", 79 | "ca-certificates", 80 | "curl", 81 | "git", 82 | "libssl-dev", 83 | "software-properties-common", 84 | "vim", 85 | ] 86 | 87 | - name: Add Docker GPG apt Key 88 | apt_key: 89 | url: https://download.docker.com/linux/ubuntu/gpg 90 | state: present 91 | 92 | - name: Add Docker Repository 93 | apt_repository: 94 | repo: deb https://download.docker.com/linux/ubuntu bionic stable 95 | state: present 96 | 97 | - name: Update apt and install docker-ce 98 | apt: update_cache=yes name=docker-ce state=latest 99 | 100 | - name: Ensure docker-compose is installed and available 101 | get_url: 102 | url: https://github.com/docker/compose/releases/download/{{ docker_compose_version }}/docker-compose-{{ ansible_system }}-{{ ansible_userspace_architecture }} 103 | dest: /usr/local/bin/docker-compose 104 | mode: "u=rwx,g=rx,o=rx" 105 | 106 | - name: Add Nodesource apt key. 107 | apt_key: 108 | url: https://keyserver.ubuntu.com/pks/lookup?op=get&fingerprint=on&search=0x1655A0AB68576280 109 | id: "68576280" 110 | state: present 111 | 112 | - name: Add NodeSource repositories for Node.js. 113 | apt_repository: 114 | repo: "{{ item }}" 115 | state: present 116 | with_items: 117 | - "deb https://deb.nodesource.com/node_{{ nodejs_version }} {{ ansible_distribution_release }} main" 118 | - "deb-src https://deb.nodesource.com/node_{{ nodejs_version }} {{ ansible_distribution_release }} main" 119 | register: node_repo 120 | 121 | - name: Update apt cache if repo was added. 122 | apt: update_cache=yes 123 | when: node_repo.changed 124 | tags: ["skip_ansible_lint"] 125 | 126 | - name: Ensure Node.js and npm are installed. 127 | apt: "name=nodejs={{ nodejs_version|regex_replace('x', '') }}* state=present" 128 | 129 | - name: "Yarn | GPG" 130 | apt_key: 131 | url: https://dl.yarnpkg.com/debian/pubkey.gpg 132 | state: present 133 | 134 | - name: "Yarn | Ensure Debian sources list file exists" 135 | file: 136 | path: /etc/apt/sources.list.d/yarn.list 137 | owner: root 138 | mode: "0644" 139 | state: touch 140 | 141 | - name: "Yarn | Ensure Debian package is in sources list" 142 | lineinfile: 143 | dest: /etc/apt/sources.list.d/yarn.list 144 | regexp: "deb http://dl.yarnpkg.com/debian/ stable main" 145 | line: "deb http://dl.yarnpkg.com/debian/ stable main" 146 | state: present 147 | 148 | - name: "Yarn | Update APT cache" 149 | apt: 150 | update_cache: yes 151 | 152 | - name: "Install Yarn" 153 | apt: 154 | name: yarn 155 | state: present 156 | install_recommends: no 157 | 158 | - git: 159 | repo: "https://github.com/reactioncommerce/reaction-development-platform.git" 160 | dest: /home/{{ create_user }}/{{reaction_dir}} 161 | version: trunk 162 | 163 | - git: 164 | repo: "https://github.com/reactioncommerce/proxy-traefik.git" 165 | dest: /home/{{ create_user }}/{{proxy_dir}} 166 | version: trunk 167 | 168 | - name: Change owner of the Reaction Platform and proxy to the newly created user 169 | command: "chown -R {{create_user}}:{{create_user}} {{reaction_dir}} {{proxy_dir}}" 170 | args: 171 | warn: false 172 | chdir: /home/{{ create_user }} 173 | 174 | - name: Change permissions of the source code directories 175 | command: "chmod -R 755 {{reaction_dir}} {{proxy_dir}}" 176 | args: 177 | warn: false 178 | chdir: /home/{{ create_user }} 179 | 180 | - name: "In the Reaction development platform directory use HTTPS protocol to clone repositories" 181 | become: yes 182 | become_user: "{{ create_user }}" 183 | replace: 184 | path: "/home/{{create_user}}/{{reaction_dir}}/config.mk" 185 | regexp: "git@github.com:" 186 | replace: "https://github.com" 187 | 188 | - name: "Build the Reaction Platform" 189 | become: yes 190 | become_user: "{{ create_user }}" 191 | command: make 192 | args: 193 | chdir: "/home/{{create_user}}/{{reaction_dir}}" 194 | 195 | - name: "Stop all Reaction development platform containers" 196 | command: make stop 197 | args: 198 | chdir: "{{ reaction_platform_path }}" 199 | 200 | - name: Create Docker network named web 201 | command: docker network create web 202 | 203 | - name: Create Docker network named internal 204 | command: docker network create internal 205 | 206 | - name: "Set DO Auth Token in Traefik's docker-compose.yml" 207 | replace: 208 | path: "{{ traefik_path}}/docker-compose.yml" 209 | regexp: "YOUR_DIGITALOCEAN_AUTH_TOKEN" 210 | replace: "{{ do_auth_token }}" 211 | 212 | - name: "Set config files path in Traefik's docker-compose.yml" 213 | replace: 214 | path: "{{ traefik_path}}/docker-compose.yml" 215 | regexp: "TRAEFIK_PATH" 216 | replace: "{{ traefik_path }}" 217 | 218 | - name: "Set the desired domain in Traefik's docker-compose.yml" 219 | replace: 220 | path: "{{ traefik_path}}/docker-compose.yml" 221 | regexp: "example.com" 222 | replace: "{{ domain }}" 223 | 224 | - name: "Set the email in Traefik's config file" 225 | replace: 226 | path: "{{ traefik_path}}/traefik.yml" 227 | regexp: "YOUR_EMAIL" 228 | replace: "{{ email }}" 229 | 230 | - name: "Set the domain in Traefik's config file" 231 | replace: 232 | path: "{{ traefik_path}}/traefik.yml" 233 | regexp: "YOUR_DOMAIN" 234 | replace: "{{ domain }}" 235 | 236 | - name: "Set correct permissions on traefik.yml" 237 | file: 238 | path: "{{ traefik_path}}/traefik.yml" 239 | mode: "600" 240 | 241 | - name: "Set correct permissions on acme.json" 242 | file: 243 | path: "{{ traefik_path}}/acme.json" 244 | mode: "600" 245 | 246 | - name: "Start Traefik" 247 | command: "docker-compose up -d" 248 | args: 249 | chdir: "{{ traefik_path }}" 250 | 251 | - name: "Copy docker-compose.override.yml files" 252 | copy: 253 | src: "{{ item.file_src }}" 254 | dest: "{{ item.file_dest }}" 255 | remote_src: yes 256 | owner: "{{ create_user }}" 257 | group: "{{ create_user }}" 258 | mode: "0644" 259 | loop: 260 | - { 261 | file_src: "{{ proxy_path }}/reaction/docker-compose.override.yml", 262 | file_dest: "{{ reaction_platform_path }}/reaction", 263 | } 264 | - { 265 | file_src: "{{ proxy_path }}/example-storefront/docker-compose.override.yml", 266 | file_dest: "{{ reaction_platform_path }}/example-storefront", 267 | } 268 | - { 269 | file_src: "{{ proxy_path }}/reaction-admin/docker-compose.override.yml", 270 | file_dest: "{{ reaction_platform_path }}/reaction-admin", 271 | } 272 | 273 | - name: "Set the desired domain in all docker-compose.override.yml files" 274 | replace: 275 | path: "{{ item }}" 276 | regexp: "example.com" 277 | replace: "{{ domain }}" 278 | loop: 279 | - "{{ reaction_platform_path }}/reaction/docker-compose.override.yml" 280 | - "{{ reaction_platform_path }}/example-storefront/docker-compose.override.yml" 281 | - "{{ reaction_platform_path }}/reaction-admin/docker-compose.override.yml" 282 | 283 | - name: "Set Reaction's environment variables" 284 | lineinfile: 285 | path: "{{ reaction_platform_path }}/reaction/.env" 286 | regexp: "^ROOT_URL" 287 | line: "ROOT_URL=https://api.{{ domain }}" 288 | 289 | - name: "Set the example storefront's environment variables" 290 | lineinfile: 291 | path: "{{ reaction_platform_path }}/example-storefront/.env" 292 | regexp: "^{{ item.variable }}" 293 | line: "{{ item.variable }}={{ item.value }}" 294 | loop: 295 | - { 296 | variable: "CANONICAL_URL", 297 | value: "https://storefront.{{ domain }}", 298 | } 299 | - { 300 | variable: "EXTERNAL_GRAPHQL_URL", 301 | value: "https://api.{{ domain }}/graphql", 302 | } 303 | 304 | - name: "Set the Reaction admin UI service environment variables" 305 | lineinfile: 306 | path: "{{ reaction_platform_path }}/reaction-admin/.env" 307 | regexp: "^{{ item.variable }}" 308 | line: "{{ item.variable }}={{ item.value }}" 309 | loop: 310 | - { 311 | variable: "ROOT_URL", 312 | value: "https://admin.{{ domain }}", 313 | } 314 | - { 315 | variable: "PUBLIC_STOREFRONT_HOME_URL", 316 | value: "https://storefront.{{ domain }}", 317 | } 318 | - { 319 | variable: "PUBLIC_I18N_BASE_URL", 320 | value: "https://api.{{ domain }}" 321 | } 322 | - { 323 | variable: "PUBLIC_FILES_BASE_URL", 324 | value: "https://api.{{ domain }}" 325 | } 326 | - { 327 | variable: "PUBLIC_GRAPHQL_API_URL_WS", 328 | value: "wss://api.{{ domain }}/graphql" 329 | } 330 | - { 331 | variable: "PUBLIC_GRAPHQL_API_URL_HTTP", 332 | value: "https://api.{{ domain }}/graphql" 333 | } 334 | 335 | - name: "Remove all Reaction Platform containers" 336 | command: make rm 337 | args: 338 | chdir: "{{ reaction_platform_path }}" 339 | 340 | - name: "Start all Reaction Platform containers" 341 | command: make start 342 | args: 343 | chdir: "{{ reaction_platform_path }}" 344 | 345 | - name: Download Lazydocker 346 | get_url: 347 | url: https://raw.githubusercontent.com/jesseduffield/lazydocker/master/scripts/install_update_linux.sh 348 | dest: /tmp 349 | 350 | - name: Install Lazydocker 351 | command: bash /tmp/install_update_linux.sh 352 | 353 | - name: Add Docker Compose aliases 354 | blockinfile: 355 | path: "/home/{{ create_user }}/.bashrc" 356 | block: | 357 | alias dc='docker-compose' 358 | # Bring all services down 359 | alias dcd='docker-compose down' 360 | # Attach to all logs of all services 361 | alias dcl='docker-compose logs -f' 362 | # Run a comand inside a running container 363 | alias dcr='docker-compose run --rm' 364 | # "Restart" all services 365 | alias dcre='docker-compose down && docker-compose up -d && docker-compose logs -f' 366 | # Bring all services up in daemon mode 367 | alias dcu='docker-compose up -d' 368 | # Bring all containers up and attach to their logs 369 | alias dcul='docker-compose up -d && docker-compose logs -f' 370 | # Remove exited containers 371 | alias dprune='docker ps -aq --no-trunc -f status=exited | xargs docker rm' 372 | # Show all running containers, with horizontal paging 373 | alias dps='docker ps -a | less -S' 374 | 375 | - name: "Source .bashrc" 376 | shell: "source /home/{{ create_user }}/.bashrc" 377 | args: 378 | executable: /bin/bash 379 | -------------------------------------------------------------------------------- /portainer/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.4" 2 | 3 | networks: 4 | web: 5 | external: 6 | name: web 7 | internal: 8 | external: 9 | name: internal 10 | 11 | services: 12 | templates: 13 | image: portainer/templates 14 | container_name: "portainer-templates" 15 | networks: 16 | - internal 17 | 18 | portainer: 19 | image: portainer/portainer 20 | restart: always 21 | container_name: "portainer-app" 22 | labels: 23 | - "traefik.backend=portainer" 24 | - "traefik.port=9000" 25 | - "traefik.frontend.rule=Host:portainer.example.com" 26 | #Automatically choose 'Manage the Docker instance where Portainer is running' by adding <--host=unix:///var/run/docker.sock> to the command 27 | command: --templates http://templates/templates.json 28 | networks: 29 | - web 30 | - internal 31 | volumes: 32 | - /var/run/docker.sock:/var/run/docker.sock 33 | - portainer-data:/data 34 | 35 | watchtower: 36 | image: v2tec/watchtower 37 | container_name: "portainer-watchtower" 38 | command: --cleanup portainer-app portainer-watchtower portainer/templates 39 | networks: 40 | - internal 41 | volumes: 42 | - /var/run/docker.sock:/var/run/docker.sock 43 | 44 | volumes: 45 | portainer-data: 46 | -------------------------------------------------------------------------------- /reaction-admin/docker-compose.override.yml: -------------------------------------------------------------------------------- 1 | version: '3.4' 2 | 3 | networks: 4 | web: 5 | external: 6 | name: web 7 | services: 8 | reaction-admin: 9 | labels: 10 | - "traefik.enable=true" 11 | - "traefik.http.routers.admin.entrypoints=http" 12 | - "traefik.http.routers.admin.rule=Host(`admin.example.com`)" 13 | - "traefik.http.middlewares.admin-https-redirect.redirectscheme.scheme=https" 14 | - "traefik.http.routers.admin.middlewares=admin-https-redirect" 15 | - "traefik.http.routers.admin-secure.entrypoints=https" 16 | - "traefik.http.routers.admin-secure.rule=Host(`admin.example.com`)" 17 | - "traefik.http.routers.admin-secure.tls=true" 18 | - "traefik.http.routers.admin-secure.service=admin" 19 | - "traefik.http.services.admin.loadbalancer.server.port=4080" 20 | - "traefik.docker.network=web" 21 | networks: 22 | web: 23 | -------------------------------------------------------------------------------- /reaction/docker-compose.override.yml: -------------------------------------------------------------------------------- 1 | version: '3.4' 2 | 3 | networks: 4 | web: 5 | external: 6 | name: web 7 | services: 8 | api: 9 | labels: 10 | - "traefik.enable=true" 11 | - "traefik.http.routers.api.entrypoints=http" 12 | - "traefik.http.routers.api.rule=Host(`api.example.com`)" 13 | - "traefik.http.middlewares.api-https-redirect.redirectscheme.scheme=https" 14 | - "traefik.http.routers.api.middlewares=api-https-redirect" 15 | - "traefik.http.routers.api-secure.entrypoints=https" 16 | - "traefik.http.routers.api-secure.rule=Host(`api.example.com`)" 17 | - "traefik.http.routers.api-secure.tls=true" 18 | - "traefik.http.routers.api-secure.service=api" 19 | - "traefik.http.services.api.loadbalancer.server.port=3000" 20 | - "traefik.docker.network=web" 21 | networks: 22 | web: 23 | mongo: 24 | labels: 25 | - "traefik.enable=false" 26 | 27 | -------------------------------------------------------------------------------- /traefik/acme.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reactioncommerce/proxy-traefik/dd287533fc7bcd897813cc0b840fd1467ef6bcad/traefik/acme.json -------------------------------------------------------------------------------- /traefik/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.4" 2 | 3 | services: 4 | traefik: 5 | image: traefik:v2.2 6 | security_opt: 7 | - no-new-privileges:true 8 | container_name: traefik 9 | restart: unless-stopped 10 | # command: 11 | # --api.insecure=true --providers.docker 12 | networks: 13 | - web 14 | - internal 15 | ports: 16 | - "80:80" 17 | - "443:443" 18 | environment: 19 | - DO_AUTH_TOKEN=YOUR_DIGITALOCEAN_AUTH_TOKEN 20 | volumes: 21 | - /etc/localtime:/etc/localtime:ro 22 | - /var/run/docker.sock:/var/run/docker.sock:ro 23 | - TRAEFIK_PATH/traefik.yml:/traefik.yml:ro 24 | - TRAEFIK_PATH/acme.json:/acme.json 25 | labels: 26 | - "traefik.enable=true" 27 | - "traefik.http.routers.traefik.entrypoints=http" 28 | - "traefik.http.routers.traefik.rule=Host(`traefik.example.com`)" 29 | # - "traefik.http.middlewares.traefik-auth.basicauth.users=USER:PASSWORD" 30 | # - "traefik.http.routers.traefik-secure.middlewares=traefik-auth" 31 | - "traefik.http.middlewares.traefik-https-redirect.redirectscheme.scheme=https" 32 | - "traefik.http.routers.traefik.middlewares=traefik-https-redirect" 33 | - "traefik.http.routers.traefik-secure.entrypoints=https" 34 | - "traefik.http.routers.traefik-secure.rule=Host(`traefik.example.com`)" 35 | - "traefik.http.routers.traefik-secure.tls=true" 36 | - "traefik.http.routers.traefik-secure.tls.certresolver=le" 37 | - "traefik.http.routers.traefik-secure.tls.domains[0].main=example.com" 38 | - "traefik.http.routers.traefik-secure.tls.domains[0].sans=*.example.com" 39 | - "traefik.http.routers.traefik-secure.service=api@internal" 40 | 41 | networks: 42 | web: 43 | external: 44 | name: web 45 | internal: 46 | external: 47 | name: internal 48 | -------------------------------------------------------------------------------- /traefik/traefik.yml: -------------------------------------------------------------------------------- 1 | api: 2 | dashboard: true 3 | 4 | entryPoints: 5 | http: 6 | address: ":80" 7 | https: 8 | address: ":443" 9 | 10 | providers: 11 | providersThrottleDuration: 2s 12 | docker: 13 | watch: true 14 | exposedByDefault: false 15 | 16 | log: {} 17 | 18 | certificatesResolvers: 19 | le: 20 | acme: 21 | # caServer: https://acme-staging-v02.api.letsencrypt.org/directory 22 | email: YOUR_EMAIL 23 | storage: acme.json 24 | dnsChallenge: 25 | provider: digitalocean 26 | delayBeforeCheck: 0 27 | --------------------------------------------------------------------------------