diff --git a/.ansible-items/inventory b/.ansible-items/inventory index fb29a74..32090d7 100644 --- a/.ansible-items/inventory +++ b/.ansible-items/inventory @@ -1,2 +1,2 @@ [host] -{{ DEPLOYMENT_USER }}@{{ DEPLOY_HOST }} ansible_connection=ssh ansible_user={{ DEPLOYMENT_USER }} \ No newline at end of file +{{ DEPLOYMENT_USER }}@{{ DEPLOY_HOSTNAME }} ansible_connection=ssh ansible_user={{ DEPLOYMENT_USER }} \ No newline at end of file diff --git a/.ansible-items/playbook.yml b/.ansible-items/playbook.yml index 76ee47d..c499f11 100644 --- a/.ansible-items/playbook.yml +++ b/.ansible-items/playbook.yml @@ -6,7 +6,7 @@ - name: Debug debug: msg: "{{ lookup('env', 'SPT_ITEMS_PATH') }}" - - name: Delete spt-item-finder before adding everything again + - name: Delete spt-items-api before adding everything again file: state: absent path: "{{ lookup('env', 'SPT_ITEMS_PATH') }}" @@ -46,7 +46,7 @@ - name: Initialize database uri: - url: "https://{{ lookup('env', 'SPT_HOSTNAME') }}/api/refresh" + url: "https://{{ lookup('env', 'SPT_ITEM_HOSTNAME') }}/api/refresh" method: GET status_code: [200, 204] timeout: 60 \ No newline at end of file diff --git a/.ansible-items/templates/.php-env.j2 b/.ansible-items/templates/.php-env.j2 index e01deb6..a5166a2 100644 --- a/.ansible-items/templates/.php-env.j2 +++ b/.ansible-items/templates/.php-env.j2 @@ -2,7 +2,7 @@ APP_NAME="Item Finder" APP_ENV=production APP_KEY= APP_DEBUG=false -APP_URL="https://{{ lookup('env', 'SPT_HOSTNAME') }}" +APP_URL="https://{{ lookup('env', 'SPT_ITEMS_HOSTNAME') }}" APP_TIMEZONE=UTC LOG_CHANNEL=stack diff --git a/.ansible-items/templates/app.blade.php.j2 b/.ansible-items/templates/app.blade.php.j2 index 178e95f..c3ed39b 100644 --- a/.ansible-items/templates/app.blade.php.j2 +++ b/.ansible-items/templates/app.blade.php.j2 @@ -3,12 +3,11 @@ - + - - + + Item Finder diff --git a/.drone-docker.yml b/.drone-docker.yml index 7367e16..657e927 100644 --- a/.drone-docker.yml +++ b/.drone-docker.yml @@ -6,7 +6,7 @@ concurrency: limit: 1 environment: - SPT_ITEMS_PATH: /var/www/html/aki/spt-item-api + SPT_ITEMS_PATH: /var/www/html/aki/spt-items-api trigger: event: @@ -23,15 +23,15 @@ steps: - name: replace hosts and user variables image: ubuntu:impish environment: - DEPLOY_HOST: - from_secret: deploy_host - SPT_HOSTNAME: - from_secret: spt_hostname + DEPLOY_HOSTNAME: + from_secret: deploy_hostname + SPT_ITEMS_HOSTNAME: + from_secret: spt_items_hostname DEPLOYMENT_USER: from_secret: deploy_username commands: - - sed -i 's/{{ SPT_HOSTNAME }}/'"$SPT_HOSTNAME"'/g' ./frontend/.env - - sed -i 's/{{ DEPLOY_HOST }}/'"$DEPLOY_HOST"'/g' ./.ansible/inventory + - sed -i 's/{{ SPT_ITEMS_HOSTNAME }}/'"$SPT_ITEMS_HOSTNAME"'/g' ./frontend/.env + - sed -i 's/{{ DEPLOY_HOSTNAME }}/'"$DEPLOY_HOSTNAME"'/g' ./.ansible/inventory - sed -i 's/{{ DEPLOYMENT_USER }}/'"$DEPLOYMENT_USER"'/g' ./.ansible/inventory - name: build frontend @@ -62,10 +62,10 @@ steps: private_key: from_secret: deploy_ssh_key environment: - DEPLOY_HOST: - from_secret: deploy_host - SPT_HOSTNAME: - from_secret: spt_hostname + DEPLOY_HOSTNAME: + from_secret: deploy_hostname + SPT_ITEMS_HOSTNAME: + from_secret: spt_items_hostname DEPLOYMENT_USER: from_secret: deploy_username when: diff --git a/.drone-kubernetes.yml b/.drone-kubernetes.yml index 2013e26..45ab387 100644 --- a/.drone-kubernetes.yml +++ b/.drone-kubernetes.yml @@ -6,7 +6,7 @@ concurrency: limit: 1 environment: - SPT_ITEMS_PATH: /var/www/html/aki/spt-item-api + SPT_ITEMS_PATH: /var/www/html/aki/spt-items-api trigger: event: @@ -17,25 +17,19 @@ trigger: - development steps: -- name: fetch and update submodules to the latest commit - image: alpine/git - commands: - - git submodule init - - git submodule update --recursive --remote - - name: replace hosts and user variables image: ubuntu:impish environment: - DEPLOY_HOST: - from_secret: deploy_host - SPT_HOSTNAME: - from_secret: spt_hostname + DEPLOY_HOSTNAME: + from_secret: deploy_hostname + SPT_ITEMS_HOSTNAME: + from_secret: spt_items_hostname DEPLOYMENT_USER: from_secret: deploy_username commands: - - sed -i 's/{{ SPT_HOSTNAME }}/'"$SPT_HOSTNAME"'/g' ./items/frontend/.env.example + - sed -i 's/{{ SPT_ITEMS_HOSTNAME }}/'"$SPT_ITEMS_HOSTNAME"'/g' ./items/frontend/.env.example - mv ./items/frontend/.env.example ./items/frontend/.env - - sed -i 's/{{ DEPLOY_HOST }}/'"$DEPLOY_HOST"'/g' ./.ansible-items/inventory + - sed -i 's/{{ DEPLOY_HOSTNAME }}/'"$DEPLOY_HOSTNAME"'/g' ./.ansible-items/inventory - sed -i 's/{{ DEPLOYMENT_USER }}/'"$DEPLOYMENT_USER"'/g' ./.ansible-items/inventory when: branch: @@ -76,10 +70,10 @@ steps: private_key: from_secret: deploy_ssh_key environment: - DEPLOY_HOST: - from_secret: deploy_host - SPT_HOSTNAME: - from_secret: spt_hostname + DEPLOY_HOSTNAME: + from_secret: deploy_hostname + SPT_ITEMS_HOSTNAME: + from_secret: spt_items_hostname DEPLOYMENT_USER: from_secret: deploy_username when: diff --git a/items/README.md b/items/README.md index 99d0fbc..229da25 100644 --- a/items/README.md +++ b/items/README.md @@ -18,8 +18,8 @@ ## Required secrets | secret name | description | example | | :-----------------| :---------- | :------- | -| spt_hostname | The remote server where spt-items-finder will be reachable
used for the frontend resolution | spt-items.my.server.com | -| deploy_host | The remote server where to deploy
used by Ansible SSH | my.server.com | +| spt_items_hostname | The remote server where spt-items-finder will be reachable
used for the frontend resolution | spt-items.my.server.com | +| deploy_hostname | The remote server where to deploy
used by Ansible SSH | my.server.com | | deploy_username | The default username on the remote server
used by Ansible SSH
This user must have sudo rights | myuser | | deploy_ssh_key | The **content** of the ssh private key used to connect to the remote server
The key needs to be in RSA in "RSA PRIVATE KEY" format
The ssh publick key needs to already be in the user used in the remote server ~/.ssh/authorized_keys | -----BEGIN RSA PRIVATE KEY-----
The key
-----END RSA PRIVATE KEY----- | diff --git a/items/docs/Walkthrough.md b/items/docs/Walkthrough.md index 7b52f9d..7df00d8 100644 --- a/items/docs/Walkthrough.md +++ b/items/docs/Walkthrough.md @@ -13,7 +13,7 @@ * [Check ansible syntax](#check-ansible-syntax) * [Apply ansible playbook](#apply-ansible-playbook) * [Playbook definition](#playbook-definition) - * [Delete old spt-item-finder](#delete-old-spt-item-finder) + * [Delete old spt-items-api](#delete-old-spt-items-api) * [Copy the project](#copy-the-project) * [Copy PHP env file](#copy-php-env-file) * [Get JavaScript chunks name](#get-javascript-chunks-name) @@ -49,7 +49,7 @@ The pipeline is set to only one build at a time (every subsequent build with be ## Environment variables ```yml environment: - SPT_ITEMS_PATH: /var/www/html/aki/spt-item-api + SPT_ITEMS_PATH: /var/www/html/aki/spt-items-api ``` Here are the environment variables. They are automatically injected in every step. @@ -79,21 +79,21 @@ Fetching and updating [submodules](https://git-scm.com/book/en/v2/Git-Tools-Subm - name: replace hosts and user variables image: ubuntu:impish environment: - DEPLOY_HOST: - from_secret: deploy_host - SPT_HOSTNAME: - from_secret: spt_hostname + DEPLOY_HOSTNAME: + from_secret: deploy_hostname + SPT_ITEMS_HOSTNAME: + from_secret: spt_items_hostname DEPLOYMENT_USER: from_secret: deploy_username commands: - - sed -i 's/{{ SPT_HOSTNAME }}/'"$SPT_HOSTNAME"'/g' ./frontend/.env - - sed -i 's/{{ DEPLOY_HOST }}/'"$DEPLOY_HOST"'/g' ./.ansible/inventory + - sed -i 's/{{ SPT_ITEMS_HOSTNAME }}/'"$SPT_ITEMS_HOSTNAME"'/g' ./frontend/.env + - sed -i 's/{{ DEPLOY_HOSTNAME }}/'"$DEPLOY_HOSTNAME"'/g' ./.ansible/inventory - sed -i 's/{{ DEPLOYMENT_USER }}/'"$DEPLOYMENT_USER"'/g' ./.ansible/inventory ``` Executed on every push. \ The following environment variables are injected using Drone secrets: - * `SPT_HOSTNAME` is used by the frontend to call the backend. - * `DEPLOY_HOST` is used by Ansible to connect to the remote server via SSH. + * `SPT_ITEMS_HOSTNAME` is used by the frontend to call the backend. + * `DEPLOY_HOSTNAME` is used by Ansible to connect to the remote server via SSH. * `DEPLOYMENT_USER` is used by Ansible to connect to the remote server via SSH. * all environment variables at the pipeline level (see [Environment variables](#environment-variables)) Using `sed` makes temporary changes in the container/pod instead of commiting secrets in the repo in plain text. \ @@ -144,10 +144,10 @@ Check the Ansible syntax in [playbook.yml](../.ansible/playbook.yml), [inventory private_key: from_secret: deploy_ssh_key environment: - DEPLOY_HOST: - from_secret: deploy_host - SPT_HOSTNAME: - from_secret: spt_hostname + DEPLOY_HOSTNAME: + from_secret: deploy_hostname + SPT_ITEMS_HOSTNAME: + from_secret: spt_items_hostname DEPLOYMENT_USER: from_secret: deploy_username when: @@ -160,8 +160,8 @@ Executed only on promotion to production. \ This step actually deploys to the server. \ This step is [idempotent](https://en.wikipedia.org/wiki/Idempotence). \ The following environment variables are injected using Drone secrets: - * `SPT_HOSTNAME` is used by the PHP env file. - * `DEPLOY_HOST` is used to connect to the remote server via SSH. + * `SPT_ITEMS_HOSTNAME` is used by the PHP env file. + * `DEPLOY_HOSTNAME` is used to connect to the remote server via SSH. * `DEPLOYMENT_USER` is used to connect to the remote server via SSH. * all environment variables at the pipeline level (see [Environment variables](#environment-variables)) @@ -174,9 +174,9 @@ become_method: sudo ``` Uses the host defined in [inventory](../.ansible/inventory). Remember, the step [Replace hosts and user variables](#replace-hosts-and-user-variables) already replaced the variables at this point. The playbook will be executed as `root` user using `sudo`. -#### Delete old spt-item-finder +#### Delete old spt-items-api ```yml -- name: Delete spt-item-finder before adding everything again +- name: Delete spt-items-api before adding everything again file: state: absent path: "{{ lookup('env', 'SPT_ITEMS_PATH') }}" @@ -202,7 +202,7 @@ Copies the whole project (frontend and backend) from the [api](../api) folder in ``` Uses [Jinja2](https://jinja2docs.readthedocs.io/en/stable/) to resolve the [template for the PHP .env file](../.ansible/templates/.php_env.j2). \ `SPT_ITEMS_PATH` is injected thanks to the pipeline level environment variables (see [Environment variables](#environment-variables)). \ -`SPT_HOSTNAME` is injected in the environments properties (see [Apply ansible playbook](#apply-ansible-playbook)) +`SPT_ITEMS_HOSTNAME` is injected in the environments properties (see [Apply ansible playbook](#apply-ansible-playbook)) #### Get JavaScript chunks name ```yml diff --git a/items/frontend/.env.example b/items/frontend/.env.example index 763195d..16a6189 100644 --- a/items/frontend/.env.example +++ b/items/frontend/.env.example @@ -1,4 +1,4 @@ -REACT_APP_BACKEND_URL=https://{{ SPT_HOSTNAME }} +REACT_APP_BACKEND_URL=https://{{ SPT_ITEMS_HOSTNAME }} REACT_APP_SPTARKOV_HOME=https://www.sp-tarkov.com/ REACT_APP_SPTARKOV_WORKSHOP=https://mods.sp-tarkov.com/ REACT_APP_SPTARKOV_DOCUMENTATION=https://docs.sp-tarkov.com/ \ No newline at end of file