Accompanying blog can be found here
- A linode api token.
- Create a .env file in the microservices folder. Add the following value
- Change the branch you need the Github Actions to run on.
MONGO_INITDB_DATABASE=admin
MONGO_INITDB_ROOT_USERNAME=root
MONGO_INITDB_ROOT_PASSWORD=example
MONGODB_CONNSTRING=mongodb://root:example@mongo:27017/test?directConnection=true&authSource=admin&replicaSet=replicaset&retryWrites=true
- In the Terraform directory create the file terraform.tfvars and add the following:
linode-token="add_token_here_within_the_quotes"
root_pass="generate_a_strong_password_and_add_it_here_between_this_quotes"
Navigate to the Scripts folder
cd Scripts
Run the bash installation script. This script installs Ansible, Terraform and ssh pass to your laptop
./installations.sh
Run the Terraform setup script that spins up a new ubuntu VM on Linode, generates ssh keys , saves the ip address on the inventory.ini, logs in to the VM and pastes the public key.
./terraform_setup.sh
Run ansible script. The Script, logs in to the VM, installs the needed modules , spins up the docker compose
./run_ansible.sh
Navigate to the Scripts folder
cd Scripts
Remove the ansible installation block.Run the bash installation script. This script installs Terraform and ssh pass to your laptop.
./installations.sh
Push the code to github. Ensure you add the following to github secrets:
MONGO_INITDB_DATABASE=admin
MONGO_INITDB_ROOT_USERNAME=root
MONGO_INITDB_ROOT_PASSWORD=example
MONGODB_CONNSTRING=mongodb://root:example@mongo:27017/test?directConnection=true&authSource=admin&replicaSet=replicaset&retryWrites=true
Copy the private key generated to github secrets.
SSH_PRIVATE_KEY=<copy-here>
View the private key using the following command
cat $HOME/.ssh/microservicekeys/id_rsa
Final github secrets should be as follows:
See the open issues for a full list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE.txt
for more information.
Tweet me at- @wamaithanyamu or shoot me an email at [email protected]
Project Link: https://github.com/wamaithanyamu/building-microservices-with-terraform-ansible-docker-dockercompose-and-github-actions