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
# Pull base image | |
FROM python:3.10 | |
# Set environment variables | |
ENV PYTHONDONTWRITEBYTECODE 1 | |
ENV PYTHONUNBUFFERED 1 | |
# Set working directory | |
WORKDIR /code |
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
#!/bin/bash | |
# When starting the django app container, we need to wait until the postgress DB is ready to receive connections | |
# docker-compose "depends_on: - db" checks the container started, but is not enough to check that the database is ready to take connections | |
# This script also accepts a command to be executed after the DB is ready (i.e. migrate, runserver or a script..) | |
function postgres_ready(){ | |
python << END | |
import sys | |
import psycopg2 | |
try: | |
print("Trying to connect to database '$DB_NAME' on host '$DB_HOST'..") |
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
version: '3.5' | |
services: | |
db: | |
image: postgres:10 | |
restart: always | |
# Optional: Map the container port to a host port to be able to connect with a local db client | |
ports: | |
- ${DB_PORT}:${DB_PORT} | |
environment: |
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
#!/bin/sh | |
echo "Running migrations.." | |
python manage.py migrate | |
echo "Starting server.." | |
python manage.py runserver 0.0.0.0:8000 |
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
\set DB_NAME `echo "$DB_NAME"` | |
\set DB_USER `echo "$DB_USER"` | |
\set DB_PASSWORD `echo "$DB_PASSWORD"` | |
CREATE USER :DB_USER WITH PASSWORD :'DB_PASSWORD'; | |
CREATE DATABASE :DB_NAME; | |
GRANT ALL PRIVILEGES ON DATABASE :DB_NAME TO :DB_USER; | |
ALTER ROLE :DB_USER CREATEDB; |
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
# Base off the official python image | |
# Define a common stage for dev and prod images called base | |
FROM python:3.10 as base | |
# Set environment variables | |
ENV PYTHONDONTWRITEBYTECODE 1 | |
ENV PYTHONUNBUFFERED 1 | |
# Create a user to avoid running containers as root in production | |
RUN addgroup --system web \ | |
&& adduser --system --ingroup web web | |
# Install os-level dependencies (as root) |
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
#!/bin/sh | |
python manage.py migrate | |
python manage.py collectstatic --noinput | |
gunicorn app.wsgi --bind 0.0.0.0:8000 --timeout 60 --access-logfile - --error-logfile - |
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
AWSTemplateFormatVersion: '2010-09-09' | |
Description: Deploy a service on AWS Fargate, hosted in a private subnet, but accessible via a public load balancer. | |
Parameters: | |
StackName: | |
Type: String | |
Default: ecs-python-sample-network | |
Description: The name of the parent Fargate networking stack that you created. Necessary | |
to locate and reference resources created by that stack. | |
ServiceName: | |
Type: String |
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
from aws_cdk import ( | |
Stack, | |
aws_ec2 as ec2, | |
aws_sqs as sqs, | |
aws_ecs as ecs, | |
aws_ecs_patterns as ecs_patterns, | |
aws_certificatemanager as acm, | |
aws_elasticloadbalancingv2 as elbv2, | |
aws_ssm as ssm | |
) |
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
from aws_cdk import ( | |
Stack, | |
aws_ec2 as ec2, | |
aws_ssm as ssm, | |
aws_ecs as ecs, | |
) | |
from constructs import Construct | |
class NetworkStack(Stack): |
OlderNewer