npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

kiss-docker-compose

v0.0.6

Published

Cheap. Simple. Fast. Move your Docker Compose application from your local machine to the cloud in 3 minutes with KISS-Docker-Compose. Cheap: All code runs on one small EC2. Simple: It runs the same way on your machine as it runs in the cloud. Fast: works

Downloads

6

Readme

KISS Docker Compose on AWS

Cheap. Simple. Fast.

Move your Docker Compose application stack from your local machine to the cloud in 3 minutes with KISS-Docker-Compose.

  • Cheap: All code runs on one EC2 instance, which means you can get swap space (unlike Fargate) and all containers share resources which can reduce unusued resource capacity. Note: Swap isn't currently configured for this project.
  • Simple: It runs the same way on your machine with Docker Compose as it runs in the cloud because both are running a Docker Compose file.
  • Fast: Deploys quickly.

Get Started

Install

npm i kiss-docker-compose
npm i aws-cdk-lib

Inline Docker Compose File

const dockerComposeFileAsString = `
services:
  frontend:
    image: nginx # used as an example / for testing
    restart: always
    # build:
    #   context: ../src/client
    ports:
    - 80:80
    volumes:
    - ./vuejs:/project
    - /project/node_modules

  backend:
    image: nginx # used as an example / for testing
    restart: always
    # build:
    #   context: ../src/server
    ports:
    - 443:80
    depends_on:
      db:
        condition: service_started

  db:
    image: postgres
    restart: always
    # set shared memory limit when using docker-compose
    shm_size: 128mb
    healthcheck:
      `+ 'test: [ "CMD-SHELL", "pg_isready -d $${POSTGRES_DB} -U $${POSTGRES_USER}" ]' + `
      interval: 15s
      timeout: 30s
      retries: 5
    ports:
      - 5432:5432
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: "password"
    volumes:
      - db-data:/var/lib/postgres

volumes:
  db-data:
`;

const kissDockerCompose = new KissDockerCompose(stack, 'kiss-docker-compose', { dockerComposeFileAsString });

// Exporting the value so you can find it easily
new cdk.CfnOutput(stack, 'Kiss-Docker-Compose-public-ip', {
  value: kissDockerCompose.ec2Instance?.instancePublicDnsName ?? '',
  exportName: 'Kiss-Docker-Compose-public-ip',
});

Load a Docker Compose File From Your File System

Get a sample Docker Compose File:

curl -O https://raw.githubusercontent.com/Gregory-Ledray/kiss-docker-compose-on-aws/main/test/docker-compose.yml

And use it:

import * as fs from 'fs';
import { KissDockerCompose } from 'kiss-docker-compose'

const dockerComposeFileAsString = fs.readFileSync('./docker-compose.yml', 'utf8');

const kissDockerCompose = new KissDockerCompose(stack, 'kiss-docker-compose', { dockerComposeFileAsString });

// Exporting the value so you can find it easily
new cdk.CfnOutput(stack, 'Kiss-Docker-Compose-public-ip', {
  value: kissDockerCompose.ec2Instance?.instancePublicDnsName ?? '',
  exportName: 'Kiss-Docker-Compose-public-ip',
});

Delete or Destroy

General Procedure:

  1. cdk destroy
  2. Find the EBS Volume which was preserved after deletion and delete it.

Detailed Procedure

  1. Run this command:
npx cdk destroy
  1. By default, the EC2 Instance preserves its root volume when deleted. You need to find this volume and delete it. It will be in the same region as the EC2 Instance.

Accidental Delection / Disaster Recovery

Lost Data

When the EC2 Instance is deleted, the volumes are saved. This is to prevent the CDK from deleting the EC2 Instance whenever you make a change and you losing all of your data. To restore your data, follow this procedure, which is also documented in TestPlan.md:

  1. Find your detatched volume. This will be in the same account and region the EC2 instance was in.
  2. Create a Snapshot from the Volume. This will take a minute or two.
  3. Create an AMI from the snapshot. Use the following settings: Some parameters: Image Name: test for restore Architecture: x86_64 Root device name: /dev/xvda Virtualization Type: Hardware-assisted virtualization Boot mode: Use default Block device mappings:
  • Volume 1: 8 GiB. gp3. 3000. 125 MB/s. Uncheck "delete on termination." Click "Create Image"
  1. When calling Kiss-Docker-Compose, set the AMI parameter. Example: src/integ.from-ami.ts
  2. Deploy. The new deployment will use the AMI which was created from your Root Volume.

Why does it work this way? Isn't this kind of roundabout? Yes, it is. I tried a variety of other approaches, but didn't get them to work. See: #3

Lost EIP

If you destroy the stack, you could lose your EIP. What do you do if the EIP was allowlisted somewhere and you need it back?

  1. You can get back the EIP by following this procedure under the heading, "Recover an Elastic IP address": https://repost.aws/knowledge-center/ec2-recover-ip-address#

  2. Do NOT pass an EIP into Kiss-Docker-Compose since there is no way to import an EIP into the CDK (right now).

  3. Perform the following work yourself after calling Kiss-Docker-Compose:

new cdk.aws_ec2.CfnEIPAssociation(this, `${id}-eip-association`, {
  allocationId: 'the-eip-allocation-id',
  instanceId: kissDockerComposeClassInstance.ec2Instance.instanceId,
});

Contributing

Update Projen

npx projen

Test

npx projen test

Build

npx projen build

Test Deployment

You may need to set some parameters since modifying src/integ.default.ts is ill advised:

export AWS_REGION=us-east-2

Deploy:

npx cdk deploy --app='./lib/integ.default.js'