Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ jobs:
uses: actions/checkout@v3
- name: Download ecs-tool
run: |
wget -O ecs-tool.tar.gz https://github.com/springload/ecs-tool/releases/download/1.9.0/ecs-tool_1.9.0_linux_amd64.tar.gz && tar -C /usr/bin -xvf ecs-tool.tar.gz ecs-tool
wget -O ecs-tool.tar.gz https://github.com/springload/ecs-tool/releases/download/v1.9.9-beta/ecs-tool_1.9.9-beta_linux_amd64.tar.gz && tar -C /usr/bin -xvf ecs-tool.tar.gz ecs-tool

- name: Deploy app
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
Expand All @@ -165,5 +166,5 @@ jobs:
VERSION=$(echo $GITHUB_SHA | cut -c -8)
echo "updating the ssm parameter with ejson configuration"
ecs-tool -p "" -e "${ENVIRONMENT}" ejson -f infra/ssm.ejson
ecs-tool -p "" -e "${ENVIRONMENT}" run --image_tag "${ENVIRONMENT}-${VERSION}" -- ./deploy.sh
ecs-tool -p "" -e "${ENVIRONMENT}" runFargate --image_tag "${ENVIRONMENT}-${VERSION}" -- ./deploy.sh
ecs-tool -p "" -e "${ENVIRONMENT}" deploy --image_tag "${ENVIRONMENT}-${VERSION}"
4 changes: 2 additions & 2 deletions docker/httpd/vhost.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
upstream app_server {
server application:8000 fail_timeout=0;
server 127.0.0.1:8000 fail_timeout=0;
}

proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=cache:10m max_size=1g
Expand All @@ -11,7 +11,7 @@ map $upstream_http_cache_control $no_cache {
}

server {
listen 8000;
listen 8080;
server_name _;
server_tokens off;
gzip on;
Expand Down
42 changes: 28 additions & 14 deletions madewithwagtail/settings/grains/aws.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
import os


import requests

from django.core.exceptions import ImproperlyConfigured

from .. import AWS_S3_CUSTOM_DOMAIN, AWS_STORAGE_BUCKET_NAME
from .django import ALLOWED_HOSTS


def _probe_aws_ip():
try:
ec2_private_ip = requests.get(
"http://169.254.169.254/latest/meta-data/local-ipv4", timeout=3
).text
except requests.exceptions.RequestException as e:
raise ValueError("Could not get EC2 private ip address: {}".format(e))
# Determine the runtime environment
if os.environ.get("ECS_CONTAINER_METADATA_URI_V4"):
# If running on Fargate with platform version 1.4.0 or later
metadata_uri = os.environ["ECS_CONTAINER_METADATA_URI_V4"]
try:
response = requests.get(f"{metadata_uri}/task", timeout=3)
response.raise_for_status() # Raise an error for bad responses
data = response.json()
# Assume the first network interface's private IP is what we need
ec2_private_ip = data["Containers"][0]["Networks"][0]["IPv4Addresses"][0]
except requests.exceptions.RequestException as e:
raise ValueError(f"Could not get Fargate task's private IP address: {e}")
else:
if not ec2_private_ip:
raise ValueError(
"Could not get EC2 private ip address: ec2_private_ip={!r}".format(
ec2_private_ip
)
)
return ec2_private_ip
# Assume running on EC2 or similar environment with access to the traditional metadata service
try:
ec2_private_ip = requests.get(
"http://169.254.169.254/latest/meta-data/local-ipv4", timeout=3
).text
except requests.exceptions.RequestException as e:
raise ValueError(f"Could not get EC2 private ip address: {e}")

if not ec2_private_ip:
raise ValueError(
f"Could not get private ip address: ec2_private_ip={ec2_private_ip!r}"
)
return ec2_private_ip


ALLOWED_HOSTS.append(_probe_aws_ip())
Expand Down
Loading