Skip to content

Commit

Permalink
Merge pull request #586 from rust-lang/playground-ubuntu-24
Browse files Browse the repository at this point in the history
Extend playground Ansible scripts for Ubuntu 24 and deploy
  • Loading branch information
shepmaster authored Sep 27, 2024
2 parents 3636f9d + 4e95c7b commit 7282f30
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 17 deletions.
3 changes: 3 additions & 0 deletions ansible/apply
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ def run_playbook(args):
ansible_args += ["--check"]
if args.diff:
ansible_args += ["--diff"]
if args.verbose > 0:
ansible_args += [f"-{'v' * args.verbose}"]

env = os.environ.copy()
# Set environment variable if running on macOS to avoid python crash
Expand Down Expand Up @@ -112,6 +114,7 @@ if __name__ == "__main__":
"--diff", help="perform an Ansible diff run",
action="store_true",
)
parser.add_argument('-v', '--verbose', action='count', default=0)
args = parser.parse_args()

install_ansible()
Expand Down
2 changes: 0 additions & 2 deletions ansible/envs/dev-example/group_vars/playground.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
---

vars_playground_domain: example.com

vars_playground_s3_bucket: bucket-name

vars_playground_aws:
Expand Down
2 changes: 0 additions & 2 deletions ansible/envs/prod/group_vars/playground.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ ssm_playground: "{{ lookup('aws_ssm', '/prod/ansible/playground/', region='us-we
vars_extra_sudo_users:
- shep

vars_playground_domain: play-1.infra.rust-lang.org

vars_playground_s3_bucket: rust-playground-artifacts

vars_playground_env_github_token: "{{ ssm_playground['github-token'] }}"
1 change: 1 addition & 0 deletions ansible/envs/prod/hosts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ crater-azure-2.infra.rust-lang.org

[playground]
play-1.infra.rust-lang.org
play-2.infra.rust-lang.org

[dev-desktop]
dev-desktop-eu-1.infra.rust-lang.org
Expand Down
7 changes: 5 additions & 2 deletions ansible/playbooks/playground.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@
dummy_certs: "{{ vars_letsencrypt_dummy_certs }}"
email: admin@rust-lang.org
domains:
- "{{ vars_playground_domain }}"
- "{{ inventory_hostname }}"

- role: nginx
worker_connections: "{{ vars_playground_number_connections }}"
proxied:
- domain: "{{ vars_playground_domain }}"
- domain: "{{ inventory_hostname }}"
to: "http://127.0.0.1:{{ vars_playground_env_ui_port }}"
websockets:
- '/websocket'
extra_locations:
- path: '/docker-metrics'
to: 'http://127.0.0.1:9323/metrics'

- role: playground
6 changes: 6 additions & 0 deletions ansible/roles/nginx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@ this role as well.
- domain: subdomain.example.com
# The destination to proxy to
to: http://localhost:8000
# Additional `location` directives to proxy, beyond the default `/` location [optional]
extra_locations:
# The location to respond to
- path: /my/awesome/location
# The URL to proxy to
to: http:127.0.0.1:9999/something
```
11 changes: 11 additions & 0 deletions ansible/roles/nginx/templates/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ http {
proxy_pass {{ proxy.to }};
}

{% for extra_location in proxy.extra_locations | default([]) %}
location {{ extra_location.path }} {
add_header Strict-Transport-Security max-age=15768000;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass {{ extra_location.to }};
}
{% endfor %}

{% for websocket in proxy.websockets | default([]) %}
location {{ websocket }} {
add_header Strict-Transport-Security max-age=15768000;
Expand Down
35 changes: 24 additions & 11 deletions ansible/roles/playground/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@

# --------------------

- name: Add Docker APT repository GPG key
apt_key:
state: present
keyserver: "https://download.docker.com/linux/{{ ansible_distribution|lower }}/gpg"
id: 7EA0A9C3F273FCD8

- name: Add Docker APT repository
apt_repository:
repo: "deb [arch=amd64] https://download.docker.com/linux/{{ ansible_distribution|lower }} {{ ansible_distribution_release }} stable"
state: present
update_cache: true
deb822_repository:
name: docker
types: deb
uris: 'https://download.docker.com/linux/{{ ansible_distribution|lower }}'
suites: '{{ ansible_distribution_release }}'
components: stable
architectures: amd64
signed_by: "https://download.docker.com/linux/{{ ansible_distribution|lower }}/gpg"

- name: Install Docker
apt:
Expand Down Expand Up @@ -67,6 +65,13 @@

# --------------------

- name: Install atop
apt:
name: atop
state: present

# --------------------

# Set up a partition with limited space to avoid temporary
# input/output files consuming all of the space on the primary
# partition.
Expand Down Expand Up @@ -116,10 +121,18 @@
repo: "{{ vars_playground_repository_url }}"
dest: "{{ vars_playground_checkout_path }}"

- name: Install awscli
- name: Install aws (Ubuntu < 24)
apt:
name: awscli
state: present
when: ansible_distribution_version is version('24', '<')

- name: Install aws (Ubuntu >= 24)
community.general.snap:
name: aws-cli
classic: true
state: present
when: ansible_distribution_version is version('24', '>=')

- name: Allow update script to restart playground
template:
Expand Down
1 change: 1 addition & 0 deletions ansible/roles/playground/templates/daemon.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"metrics-addr": "127.0.0.1:9323",
"cgroup-parent": "playground.slice",
"log-driver": "local",
"storage-driver": "overlay2"
Expand Down

0 comments on commit 7282f30

Please sign in to comment.