1. Answers
  2. Deploy ArgoCD Docker Image on AWS EC2 with TypeScript

How do I deploy the ArgoCD Docker image on AWS EC2 with TypeScript?

In this guide, we will deploy the ArgoCD Docker image on an AWS EC2 instance using Pulumi with TypeScript. We will set up the necessary resources including a VPC, security group, and an EC2 instance configured to run the ArgoCD Docker container.

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

// Create a new VPC
const vpc = new aws.ec2.Vpc("vpc", {
    cidrBlock: "10.0.0.0/16",
});

// Create a subnet in the VPC
const subnet = new aws.ec2.Subnet("subnet", {
    vpcId: vpc.id,
    cidrBlock: "10.0.1.0/24",
    availabilityZone: "us-west-2a",
});

// Create an internet gateway for the VPC
const internetGateway = new aws.ec2.InternetGateway("internetGateway", {
    vpcId: vpc.id,
});

// Create a route table
const routeTable = new aws.ec2.RouteTable("routeTable", {
    vpcId: vpc.id,
    routes: [
        {
            cidrBlock: "0.0.0.0/0",
            gatewayId: internetGateway.id,
        },
    ],
});

// Associate the route table with the subnet
new aws.ec2.RouteTableAssociation("routeTableAssociation", {
    subnetId: subnet.id,
    routeTableId: routeTable.id,
});

// Create a security group
const securityGroup = new aws.ec2.SecurityGroup("securityGroup", {
    vpcId: vpc.id,
    description: "Allow HTTP and SSH",
    ingress: [
        {
            protocol: "tcp",
            fromPort: 80,
            toPort: 80,
            cidrBlocks: ["0.0.0.0/0"],
        },
        {
            protocol: "tcp",
            fromPort: 22,
            toPort: 22,
            cidrBlocks: ["0.0.0.0/0"],
        },
    ],
    egress: [
        {
            protocol: "tcp",
            fromPort: 0,
            toPort: 0,
            cidrBlocks: ["0.0.0.0/0"],
        },
    ],
});

// Get the latest Amazon Linux 2 AMI
const ami = aws.ec2.getAmi({
    filters: [
        { name: "name", values: ["amzn2-ami-hvm-*-x86_64-gp2"] },
    ],
    owners: ["137112412989"], // Amazon
    mostRecent: true,
});

// Create an EC2 instance
const ec2Instance = new aws.ec2.Instance("ec2Instance", {
    instanceType: "t2.micro",
    ami: ami.then(ami => ami.id),
    subnetId: subnet.id,
    vpcSecurityGroupIds: [securityGroup.id],
    associatePublicIpAddress: true,
    userData: `#!/bin/bash
    yum update -y
    amazon-linux-extras install docker -y
    service docker start
    usermod -a -G docker ec2-user
    docker run -d -p 80:8080 argoproj/argocd`,
    tags: {
        Name: "ArgoCD-EC2",
    },
});

// Export the public IP of the instance
export const publicIp = ec2Instance.publicIp;
export const publicDns = ec2Instance.publicDns;

Key Points

  • We created a new VPC and subnet to host our EC2 instance.
  • An internet gateway and route table were set up to allow internet access.
  • A security group was configured to allow HTTP (port 80) and SSH (port 22) traffic.
  • An EC2 instance was launched using the latest Amazon Linux 2 AMI.
  • The EC2 instance was configured to install Docker, start the Docker service, and run the ArgoCD Docker container.

Summary

We successfully deployed the ArgoCD Docker image on an AWS EC2 instance using Pulumi with TypeScript by setting up the necessary VPC, subnet, internet gateway, route table, security group, and EC2 instance. The instance is configured to run the ArgoCD Docker container, making it accessible via HTTP.

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up