This repository contains a simple CI/CD project that automates the process of building a Docker image on self-hosted GitHub Runner, pushing it to Docker Hub, creating infrastructure on AWS, installing and deploying the Docker image to an EC2 instance.
- JavaScript
- Docker
- Terraform
- Ansible
- GitHub Actions
- AWS
- AWS Account:
- Create a new user
- Create key pair
- DockerHub Account:
- Create a new repository
- Create Terraform Cloud Account:
- Create a new organization
- Create a new project in organization
- Create a new workspace in project
- Change backend block in root's providers.tf to your configuration:
backend "remote" { organization = "YourOrgName" workspaces { name = "YourWorkspaceName" } }
- Set up GitHub Runner in your project
- Prepare VM for self-hosted GitHub Runner:
- Install self-hosted GitHub Runner, terrafom, ansible and docker
- Save AWS SSH private key file generated in 1st step in your user's .ssh folder
- Setup GitHub project secrets:
- AWS_ACCESS_KEY_ID - your AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY - your AWS_SECRET_ACCESS_KEY
- DOCKER_PASSWORD - your DockerHub account password
- DOCKER_USERNAME - your DockerHub account name
- SSH_KEY - content of AWS SSH private key generated in 1st step for Ansible to connect to EC2. e.g., raw content
- SSH_USERNAME - ssh username
- TFVARS_FILE - edit terraform.tfvars.template and copy all content into this secret
- Clone/fork this project