Giter Club home page Giter Club logo

mastodon-terraform's Introduction

mastodon-terraform

Boilerplate for running Mastodon on AWS using Terraform and CircleCI.

┌---------------┐
|  Web Browser  |
└---------------┘
▲               ▲
|               |
(HTTPS)         (WebSocket)
|               |
▼               |
┌------------┐  |
| CloudFront |  |
└------------┘  |
▲               |
|               |
(HTTP)          |
|               |
▼               ▼
┌---------------┐
|      ALB      |
└---------------┘
▲               ▲
|               |
(HTTP)          (WebSocket)
|               |
▼               ▼
┌------------------------┐
| ┌-Docker-┐ ┌-Docker--┐ |
| |  Puma  | | Express | |
| └--------┘ └---------┘ |
| ┌-Docker--┐            |
| | Sidekiq |     EC2    |
| └---------┘            |
└------------------------┘
▲                  ▲
|                  |
▼                  ▼
┌----------------┐ ┌-------------┐
| ┌------------┐ | |  ┌-------┐  |
| | PostgreSQL | | |  | Redis |  |
| └------------┘ | |  └-------┘  |
|       RDS      | | Elasticache |
└----------------┘ └-------------┘

Usage

  1. Fork this repository
  2. Enable CircleCI integration
  3. Set environment variables on CircleCI
  4. Run CircleCI job to create resources on AWS
  5. Build and push mastodon docker image via mastodon-docker
  6. Run rails db:setup by running custom ECS task on AWS console

Required environment variables

AWS_ACCESS_KEY_ID

AWS IAM User access key ID for Terraform.

e.g. ABCDEFGHIJKLMNOPQRST

AWS_DEFAULT_REGION

AWS region that the resources will be located in.

e.g. ap-northeast-1

AWS_SECRET_ACCESS_KEY

AWS IAM User secret access key for Terraform.

e.g. abcdefghijklmnopqrstuvwxyz0123456789/+AB

TF_VAR_mastodon_db_pass

Database password.

e.g. Generate a long random value like this:

ruby -r securerandom -e "puts SecureRandom.hex(64)"

TF_VAR_mastodon_docker_image_tag

Mastodon Docker image tag to detect which image to be deployed on ECS. If you are using mastodon-docker to build and push it to ECR, the CircleCI build number will be the Docker image tag.

e.g. 123

Note: this variable is not required at the 1st time because we need to create ECR repository before building Mastodon Docker image.

TF_VAR_mastodon_otp_secret

One-time password secret

e.g. Generate a long random value like this:

ruby -r securerandom -e "puts SecureRandom.hex(64)"

TF_VAR_mastodon_secret_key_base

The secret key base.

e.g. Generate a long random value like this:

ruby -r securerandom -e "puts SecureRandom.hex(64)"

Optional environment variables

TF_VAR_aws_ecs_task_definition_mastodon_node_streaming_memory

Memory size for node_streaming ECS task.

default: 300

TF_VAR_aws_ecs_task_definition_mastodon_rails_db_migration_memory

Memory size for rails_db_migration ECS task.

default: 300

TF_VAR_aws_ecs_task_definition_mastodon_rails_db_set_up_memory

Memory size for rails_db_set_up ECS task.

default: 300

TF_VAR_aws_ecs_task_definition_mastodon_rails_puma_memory

Memory size for rails_puma ECS task.

default: 300

TF_VAR_aws_ecs_task_definition_mastodon_rails_sidekiq_memory

Memory size for rails_sidekiq ECS task.

default: 300

TF_VAR_mastodon_aws_access_key_id

AWS IAM user access key ID for Rails to access to AWS API.

TF_VAR_mastodon_aws_secret_access_key

AWS IAM user secret access key for Rails to access to AWS API.

TF_VAR_mastodon_db_name

DB name.

default: mastodon

TF_VAR_mastodon_db_user

DB user name.

default: root

TF_VAR_mastodon_default_locale

Default locale.

default: en

Others

  • TF_VAR_mastodon_email_domain_blacklist
  • TF_VAR_mastodon_email_domain_whitelist
  • TF_VAR_mastodon_local_domain
  • TF_VAR_mastodon_local_https
  • TF_VAR_mastodon_node_env
  • TF_VAR_mastodon_node_streaming_api_base_url
  • TF_VAR_mastodon_node_streaming_cluster_num
  • TF_VAR_mastodon_node_streaming_log_level
  • TF_VAR_mastodon_node_streaming_port
  • TF_VAR_mastodon_paperclip_root_path
  • TF_VAR_mastodon_paperclip_root_url
  • TF_VAR_mastodon_paperclip_secret
  • TF_VAR_mastodon_prepared_statements
  • TF_VAR_mastodon_s3_bucket
  • TF_VAR_mastodon_s3_cloudfront_host
  • TF_VAR_mastodon_s3_enabled
  • TF_VAR_mastodon_s3_endpoint
  • TF_VAR_mastodon_s3_hostname
  • TF_VAR_mastodon_s3_protocol
  • TF_VAR_mastodon_s3_region
  • TF_VAR_mastodon_single_user_mode
  • TF_VAR_mastodon_smtp_auth_method
  • TF_VAR_mastodon_smtp_delivery_method
  • TF_VAR_mastodon_smtp_domain
  • TF_VAR_mastodon_smtp_enable_starttls_auto
  • TF_VAR_mastodon_smtp_from_address
  • TF_VAR_mastodon_smtp_login
  • TF_VAR_mastodon_smtp_openssl_verify_mode
  • TF_VAR_mastodon_smtp_password
  • TF_VAR_mastodon_smtp_port
  • TF_VAR_mastodon_smtp_server

Resources

This boilerplate will create the following resources:

  • module.mastodon.aws_alb_listener.mastodon_node_streaming:
  • module.mastodon.aws_alb_listener.mastodon_rails_puma:
  • module.mastodon.aws_alb_target_group.mastodon_node_streaming:
  • module.mastodon.aws_alb_target_group.mastodon_rails_puma:
  • module.mastodon.aws_alb.mastodon:
  • module.mastodon.aws_autoscaling_group.mastodon:
  • module.mastodon.aws_cloudfront_distribution.mastodon:
  • module.mastodon.aws_cloudwatch_log_group.mastodon:
  • module.mastodon.aws_db_instance.mastodon:
  • module.mastodon.aws_db_parameter_group.mastodon:
  • module.mastodon.aws_db_subnet_group.mastodon:
  • module.mastodon.aws_ecr_repository.mastodon:
  • module.mastodon.aws_ecs_cluster.mastodon:
  • module.mastodon.aws_ecs_service.mastodon_node_streaming:
  • module.mastodon.aws_ecs_service.mastodon_rails_puma:
  • module.mastodon.aws_ecs_service.mastodon_rails_sidekiq:
  • module.mastodon.aws_ecs_task_definition.mastodon_node_streaming:
  • module.mastodon.aws_ecs_task_definition.mastodon_rails_db_migration:
  • module.mastodon.aws_ecs_task_definition.mastodon_rails_db_set_up:
  • module.mastodon.aws_ecs_task_definition.mastodon_rails_puma:
  • module.mastodon.aws_ecs_task_definition.mastodon_rails_sidekiq:
  • module.mastodon.aws_elasticache_cluster.mastodon:
  • module.mastodon.aws_elasticache_subnet_group.mastodon:
  • module.mastodon.aws_iam_instance_profile.mastodon:
  • module.mastodon.aws_iam_policy_attachment.mastodon_ecs_ec2_instance:
  • module.mastodon.aws_iam_policy_attachment.mastodon_ecs_service:
  • module.mastodon.aws_iam_role.mastodon_ec2:
  • module.mastodon.aws_iam_role.mastodon_ecs:
  • module.mastodon.aws_internet_gateway.mastodon:
  • module.mastodon.aws_launch_configuration.mastodon:
  • module.mastodon.aws_route_table_association.mastodon_a:
  • module.mastodon.aws_route_table_association.mastodon_c:
  • module.mastodon.aws_route_table.mastodon:
  • module.mastodon.aws_security_group.mastodon_alb:
  • module.mastodon.aws_security_group.mastodon_db:
  • module.mastodon.aws_security_group.mastodon_elasticache:
  • module.mastodon.aws_security_group.mastodon_web:
  • module.mastodon.aws_subnet.mastodon_private_a:
  • module.mastodon.aws_subnet.mastodon_private_c:
  • module.mastodon.aws_subnet.mastodon_public_a:
  • module.mastodon.aws_subnet.mastodon_public_c:
  • module.mastodon.aws_vpc.mastodon:

Contributing

Pull Requests are welcome if you found bugs or features you think are missing.

mastodon-terraform's People

Contributors

r7kamura avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.