-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Self hosting! #67
Merged
Merged
Self hosting! #67
Changes from 12 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
899785c
only use root_domain variable for local dev
eriktaubeneck 80c801b
move existing helper deployment scripts into sidecar subdirectory
eriktaubeneck d45e2d7
add traefik config for draft frontend server
eriktaubeneck 976f6fe
add ansible deployment for draft frontend
eriktaubeneck d4635ae
move ansible directory as subdirectory of server and sidecar directories
eriktaubeneck a3af04b
add inventory variables
eriktaubeneck fd88465
fix variable name for env variable, remove unneeded nginx
eriktaubeneck f4d2c12
bug hunt
eriktaubeneck faf2a2a
try pm2 instead of systemctl
eriktaubeneck 3dc4b7d
traefik running location bug
eriktaubeneck b5460cf
fat finger domain name
eriktaubeneck 44da939
use ansible git module correctly
eriktaubeneck 135fd9b
update ansible to load put secrets in environment not .env file
eriktaubeneck dbbcfe9
fix bugs in load_secrets script
eriktaubeneck c3adf6f
restart in deploy.yaml
eriktaubeneck de07957
make sure git checks out main branch
eriktaubeneck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,8 @@ coverage/* | |
next.config.js | ||
tsconfig.json | ||
babel.config.js | ||
|
||
traefik/* | ||
ansible/* | ||
|
||
# Not JS | ||
README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
- name: Deploy updates to Draft | ||
hosts: all | ||
tasks: | ||
|
||
- name: Pull new commits from GitHub | ||
git: | ||
repo: 'https://github.com/private-attribution/draft.git' | ||
dest: '{{ ansible_env.HOME }}/draft' | ||
update: yes | ||
|
||
- name: Install packages based on package-lock.json via npm | ||
npm: | ||
path: '{{ ansible_env.HOME}}/draft/server' | ||
state: present | ||
ci: true | ||
|
||
- name: Load .env file | ||
shell: > | ||
aws secretsmanager get-secret-value | ||
--secret-id {{ env_secret_id }} | ||
--region {{ aws_region }} | ||
--query SecretString | ||
--output text | | ||
akoshelev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
jq -r 'to_entries|map("\(.key)=\"\(.value|tostring)\"")|.[]' > | ||
.env | ||
args: | ||
chdir: '{{ ansible_env.HOME }}/draft/server' | ||
executable: /bin/bash | ||
|
||
|
||
- name: Rebuild draft website | ||
shell: > | ||
npm run build | ||
args: | ||
chdir: '{{ ansible_env.HOME }}/draft/server' | ||
executable: /bin/bash | ||
|
||
|
||
- name: Restart draft website | ||
shell: > | ||
npm run pm2-restart | ||
args: | ||
chdir: '{{ ansible_env.HOME }}/draft/server' | ||
executable: /bin/bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[myhosts] | ||
draft-ipa draft_domain=draft.ipa-helper.dev draft_port=3000 env_secret_id=prod-draft-env aws_region=us-west-2 | ||
|
||
[myhosts:vars] | ||
ansible_python_interpreter=/usr/bin/python3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
- name: Setup Draft frontend | ||
hosts: all | ||
tasks: | ||
- name: Store HOME directory | ||
debug: | ||
var: ansible_env.HOME | ||
|
||
- name: Check if Node.js is installed | ||
command: node --version | ||
register: node_installed | ||
failed_when: false | ||
changed_when: false | ||
|
||
- name: Install Node.js Package Manager | ||
yum: | ||
name: nodejs | ||
state: latest | ||
become: yes | ||
when: node_installed.rc != 0 | ||
|
||
- name: Check if npm is installed | ||
command: npm --version | ||
register: npm_installed | ||
failed_when: false | ||
changed_when: false | ||
|
||
- name: Install Node.js Package Manager | ||
yum: | ||
name: npm | ||
state: latest | ||
become: yes | ||
when: npm_installed.rc != 0 | ||
|
||
- name: Check if Git is installed | ||
command: git --version | ||
register: git_installed | ||
failed_when: false | ||
changed_when: false | ||
|
||
- name: Install Git | ||
yum: | ||
name: git | ||
state: latest | ||
become: yes | ||
when: git_installed.rc != 0 | ||
|
||
- name: Clone repository if it doesn't exist | ||
git: | ||
repo: 'https://github.com/private-attribution/draft.git' | ||
dest: '{{ ansible_env.HOME }}/draft' | ||
|
||
- name: Install packages based on package-lock.json via npm | ||
npm: | ||
path: '{{ ansible_env.HOME}}/draft/server' | ||
state: present | ||
ci: true | ||
|
||
- name: Check if Traefik is installed | ||
command: '{{ ansible_env.HOME }}/draft/traefik version' | ||
register: traefik_installed | ||
failed_when: false | ||
changed_when: false | ||
|
||
- name: Download Traefik | ||
get_url: | ||
url: 'https://github.com/traefik/traefik/releases/download/v2.11.0/traefik_v2.11.0_linux_amd64.tar.gz' | ||
dest: '{{ ansible_env.HOME }}/traefik_v2.11.0_linux_amd64.tar.gz' | ||
checksum: 'sha256:7f31f1cc566bd094f038579fc36e354fd545cf899523eb507c3cfcbbdb8b9552' | ||
when: traefik_installed.rc != 0 | ||
|
||
- name: Ensure extraction directory exists | ||
file: | ||
path: '{{ ansible_env.HOME }}/traefix_extract/' | ||
state: directory | ||
|
||
- name: Extract Traefik | ||
unarchive: | ||
src: '{{ ansible_env.HOME }}/traefik_v2.11.0_linux_amd64.tar.gz' | ||
dest: '{{ ansible_env.HOME }}/traefix_extract/' | ||
remote_src: yes | ||
when: traefik_installed.rc != 0 | ||
|
||
- name: Copy Traefik binary into draft directory | ||
copy: | ||
src: '{{ ansible_env.HOME }}/traefix_extract/traefik' | ||
dest: '{{ ansible_env.HOME }}/draft' | ||
mode: '0775' | ||
remote_src: yes | ||
|
||
- name: Grant CAP_NET_BIND_SERVICE capability to traefik binary | ||
command: 'setcap cap_net_bind_service=+ep {{ ansible_env.HOME }}/draft/traefik' | ||
become: yes | ||
|
||
- name: Create cert directory | ||
file: | ||
path: '{{ ansible_env.HOME }}/cert' | ||
state: directory | ||
|
||
- name: Load cert.pem file | ||
shell: > | ||
aws secretsmanager get-secret-value | ||
--secret-id cert.pem | ||
--region {{ aws_region }} | ||
--query SecretString | ||
--output text > cert.pem | ||
args: | ||
chdir: '{{ ansible_env.HOME }}/cert' | ||
executable: /bin/bash | ||
|
||
|
||
- name: Load key.pem file | ||
shell: > | ||
aws secretsmanager get-secret-value | ||
--secret-id key.pem | ||
--region {{ aws_region }} | ||
--query SecretString | ||
--output text > key.pem | ||
args: | ||
chdir: '{{ ansible_env.HOME }}/cert' | ||
executable: /bin/bash | ||
|
||
- name: start traefik and nextjs | ||
shell: > | ||
npm run pm2-start | ||
environment: | ||
CERT_DIR: '{{ ansible_env.HOME }}/cert/' | ||
DRAFT_DOMAIN: '{{ draft_domain }}' | ||
DRAFT_PORT: '{{ draft_port }}' | ||
|
||
args: | ||
chdir: '{{ ansible_env.HOME }}/draft/server' | ||
executable: /bin/bash |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please help me understand what is getting stored in
.env
file here? According to cli docIf that's true, I am a little nervous about keeping the secret on durable storage. Is it possible to configure env variable or (probably better) assume role on this instance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's variables needed server side like API keys, db passwords, etc. We could certainly set these as environmental variables instead of using the
.env
file, and it seems reasonable to avoid writing them to a file.When you say "assume role on this instance
, this does assume a specific AMI role, which is what allows the
aws secretmanager` cli to actually access those secrets. Is there something else you mean by this?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, fixed. I added a shell script "load_secrets.sh" which is sourced and adds them into the env. the TLS keys are still written to disk, because traefik expects them there. it's not immediately obvious of a better way to handle that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you!
Yea I was thinking about using https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sts/assume-role.html to get temporary credentials, but this serves different purpose as far as I can tell.
If we store more than one password, API key, etc, we could consider partitioning this and store one secret with one key