Home Web Front-end JS Tutorial Automated Deployments of Meteor.js bundle using Terraform

Automated Deployments of Meteor.js bundle using Terraform

Dec 20, 2024 am 08:52 AM

Automated Deployments of Meteor.js bundle using Terraform

Automating Deployment on EC2 Instance with Terraform and Docker

Hey buddy! Tech can be tricky, but you’ve got this. Think of this as a tech chat over coffee...or my personal favorite, chaay (tea).

Let’s dive into how to automate deploying your Meteor.js project on AWS. By the end of this, you’ll feel like a cloud deployment ninja. Ready? Let’s go!

What You’ll Need

Before we roll up our sleeves, let’s gather our stuffff. Here's the checklist:

  1. AWS Credentials: Ensure you have the AWS CLI configured and ready to roll.

  2. Terraform: Download and install Terraform if you haven’t already.

  3. SSH Key Pair: Generate an SSH key pair. Keep the private key handy to connect to your instance later.

  4. Domain Name: Got a domain? Great! Make sure you can update its A records.

  5. Meteor Bundle: Prep your Meteor.js project bundle using this command:

   meteor build --server-only --directory ~/path/to/Dockerfile
Copy after login
Copy after login
  1. Setup Scripts: You’ll need three scripts to set up the server:
  • server-setup-part1.sh
  • mongodb4-setup.sh
  • server-setup-part2.sh

Got everything? Awesome! Let’s start building.

The Game Plan

Here’s the journey we’re about to go on:

  1. Use Terraform to spin up an EC2 instance on AWS.
  2. Run some scripts to configure the server, install MongoDB, and deploy your Meteor.js app using Docker.
  3. Tweak your DNS settings to point your domain to the server’s IP.
  4. Finalize everything with SSL setup via Certbot.

Easy enough, right? Let’s break it down step by step.


Setting Up Terraform

Start by organizing your Terraform project. Create a directory structure like this:

project-directory/
├── main.tf
├── variables.tf
├── outputs.tf
├── run.sh
Copy after login
Copy after login

Step 1: Variables Configuration

In variables.tf, define all the variables we’ll need. These make the setup flexible:

variable "server_name" {
  description = "Server created by Terraform"
  type        = string
  default     = "AutomatedDeployment"
}

variable "key_pair_name" {
  description = "Key pair name"
  type        = string
  default     = "tf-key-pair"
}

variable "domain_name" {
  description = "Your domain name"
  type        = string
  default     = "xyz.domain.com"
}
Copy after login
Copy after login

Step 2: The Heart — main.tf

Here’s where the magic happens. This file sets up everything: EC2 instance, security groups, and provisioning steps.

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 4.16"
    }
  }
  required_version = ">= 1.2.0"
}

provider "aws" {
  region = "ca-central-1"
}

resource "aws_security_group" "tf-security-group" {
  name        = var.server_name
  description = "Security group for ${var.server_name}"

  ingress {
    from_port   = 22
    to_port     = 22
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }
  ingress {
    from_port   = 80
    to_port     = 80
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }
  ingress {
    from_port   = 443
    to_port     = 443
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }
  egress {
    from_port   = 0
    to_port     = 0
    protocol    = "-1"
    cidr_blocks = ["0.0.0.0/0"]
  }
}

resource "aws_instance" "tf-created-instance" {
  ami           = "ami-0083d3f8b2a6c7a81"
  instance_type = "t2.micro"
  key_name      = var.key_pair_name
  tags = {
    Name = var.server_name
  }
}
Copy after login

Step 3: Outputs

Define what Terraform should output after running:

output "public_ip" {
  value       = aws_instance.tf-created-instance.public_ip
  description = "The public IP address of the instance"
}
Copy after login

Step 4: Automation Script

In run.sh, write a script to automate Terraform commands and handle DNS propagation:

#!/bin/bash
set -e
DOMAIN="your.domain.com"

terraform apply -auto-approve

echo "Waiting for DNS propagation..."
OLD_IP=$(dig +short $DOMAIN)
while true; do
  sleep 10
  NEW_IP=$(dig +short $DOMAIN)
  [ "$NEW_IP" != "$OLD_IP" ] && break
  echo "DNS records not updated yet. Retrying..."
done

terraform apply -auto-approve
Copy after login

Dockerfile for Meteor

Here’s a sample Dockerfile to package your Meteor.js app:

   meteor build --server-only --directory ~/path/to/Dockerfile
Copy after login
Copy after login

Steps to Deploy

  1. Initialize Terraform: Run this command to set up Terraform:
project-directory/
├── main.tf
├── variables.tf
├── outputs.tf
├── run.sh
Copy after login
Copy after login
  1. Deploy with Automation: Run the script to deploy:
variable "server_name" {
  description = "Server created by Terraform"
  type        = string
  default     = "AutomatedDeployment"
}

variable "key_pair_name" {
  description = "Key pair name"
  type        = string
  default     = "tf-key-pair"
}

variable "domain_name" {
  description = "Your domain name"
  type        = string
  default     = "xyz.domain.com"
}
Copy after login
Copy after login
  1. DNS Update:
    Update your domain’s A record to point to the EC2 instance’s public IP.

  2. Verify:
    Once DNS propagation is complete, verify your deployment by visiting the domain in a browser.


And there you have it! A fully automated Meteor.js app deployment on AWS using Terraform and Docker. Remember, every challenge is just another opportunity to learn. If you hit a rock, take a sip of chaay and troubleshoot like the tech pro you are. Celebrate your deployment success and post it everywhere!?

The above is the detailed content of Automated Deployments of Meteor.js bundle using Terraform. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What should I do if I encounter garbled code printing for front-end thermal paper receipts? What should I do if I encounter garbled code printing for front-end thermal paper receipts? Apr 04, 2025 pm 02:42 PM

Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

Demystifying JavaScript: What It Does and Why It Matters Demystifying JavaScript: What It Does and Why It Matters Apr 09, 2025 am 12:07 AM

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

Who gets paid more Python or JavaScript? Who gets paid more Python or JavaScript? Apr 04, 2025 am 12:09 AM

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

How to achieve parallax scrolling and element animation effects, like Shiseido's official website?
or:
How can we achieve the animation effect accompanied by page scrolling like Shiseido's official website? How to achieve parallax scrolling and element animation effects, like Shiseido's official website? or: How can we achieve the animation effect accompanied by page scrolling like Shiseido's official website? Apr 04, 2025 pm 05:36 PM

Discussion on the realization of parallax scrolling and element animation effects in this article will explore how to achieve similar to Shiseido official website (https://www.shiseido.co.jp/sb/wonderland/)...

The Evolution of JavaScript: Current Trends and Future Prospects The Evolution of JavaScript: Current Trends and Future Prospects Apr 10, 2025 am 09:33 AM

The latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.

Is JavaScript hard to learn? Is JavaScript hard to learn? Apr 03, 2025 am 12:20 AM

Learning JavaScript is not difficult, but it is challenging. 1) Understand basic concepts such as variables, data types, functions, etc. 2) Master asynchronous programming and implement it through event loops. 3) Use DOM operations and Promise to handle asynchronous requests. 4) Avoid common mistakes and use debugging techniques. 5) Optimize performance and follow best practices.

How to merge array elements with the same ID into one object using JavaScript? How to merge array elements with the same ID into one object using JavaScript? Apr 04, 2025 pm 05:09 PM

How to merge array elements with the same ID into one object in JavaScript? When processing data, we often encounter the need to have the same ID...

How to implement panel drag and drop adjustment function similar to VSCode in front-end development? How to implement panel drag and drop adjustment function similar to VSCode in front-end development? Apr 04, 2025 pm 02:06 PM

Explore the implementation of panel drag and drop adjustment function similar to VSCode in the front-end. In front-end development, how to implement VSCode similar to VSCode...

See all articles