In This Series: Deploy Docker to EC2
- Deploy Docker to EC2: Pull Request Environments [Part 1]
- Deploy Docker to EC2: Root Domain Deploy [Part 2]
This Github action contains a lot of features, and in this blog, we’ll show you how to tweak it to make use of the possibility of deploying your application to the root domain by using an existing domain in your AWS account.
If you’re new to the Deploy Docker to EC2 GitHub Action, check out this post!
Let’s get started! Check out the quick start video for this feature!
Prerequisites
-
A working Docker deployment. (Your files + docker-compose.yaml, optionally a Dockerfile)
-
A registered domain in AWS.
For this article, assume you already have a running Github action and there is no need to create a new workflow. If you do not have a running workflow, check the first blog for these series!
For more details on hooking up Docker for your app, check out our Academy post: Learn Docker
What does deploying to the root domain mean?
When you deploy your application, it will be located at the top level of your domain, e.g. example.com
, with the possibility of managing the certificates for this domain through the deployment itself.
The GitHub Action also allows you to use a sub-domain and create a certificate just for the sub-domain, or you can use an existing certificate. Check the note about certificates here if you’re looking to set them up!
Keep in mind that destroying the stack will also destroy any certificate it created!
Summary of Work
In this example, you will be adding the option to deploy to a root domain, and create the root certificates into our existing Github action yaml file.
Check the special note about certificates here.
1. Adjust your workflow
To deploy the application to the root domain using the deploy-docker-to-ec2 action, all you need to do is add the inputs at the bottom of this workflow (See the sections below #Domain deploy definitions
). This is a slight modification to the file created in the first blog in this series..
This file should be under your repo’s
.github/workflows
directory.
.github/workflows/deploy.yaml
name: Deploy
on:
push:
branches: [ main ]
jobs:
EC2-Deploy:
runs-on: ubuntu-latest
environment:
name: ${{ github.ref_name }}
url: ${{ steps.deploy.outputs.vm_url }}
steps:
- id: deploy
name: Deploy
uses: bitovi/github-actions-deploy-docker-to-ec2@v0.5.0
with:
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID}}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY}}
aws_default_region: us-east-1
app_port: 3000
# Domain deploy definitions
domain_name: example.com
root_domain: true
# Optional - handle root certificate creation
create_root_cert: true
There are other existing options, like using an existing domain certificate by providing the cert_arn
, deploying to a sub_domain
, specifying create_root_cert
or create_sub_cert
. Check the docs for the input options!
When the deployment is done, you will see an output summary, like in the image below, containing the link to your just-deployed application. (Keep in mind it might take a few minutes for DNS to propagate and/or application to start.)
Conclusion
Now you can deploy your application to the domain you need! You’re now well on your way to getting value from GitHub as a Platform Engineering platform! With Bitovi’s Deploy Docker to EC2 action, you and your team can quickly iterate and prototype in your own cloud provider account!
Need Help?
Drop into Community Discord and let us know! Bitovians (and our community) love to solve problems and chat about exciting projects.
Need DevOps Consulting or Platform Engineering services ? Bitovi has DevOps consultants who can assist with all aspects of your development and DevOps journey.