- Java 11
- Docker
- Terraform 1.3.0 or higher
- AWS CLI & AWS Account
./gradlew clean buildjava -jar -Dspring.profiles.active=dev build/libs/spring-boot-features-exploration-0.0.1-SNAPSHOT.jarNotice, for ARM64 platforms(e.g. M1 processor) the following flag
has to be applied for build and run commands: --platform=linux/amd64.
Another option is to replace Dockerfile in root directory with the one in arm64 directory.
./gradlew clean builddocker build -t spring-boot-feature-exploration:1.0 .docker run -d -p 8080:8080 -e "SPRING_PROFILES_ACTIVE=dev" spring-boot-feature-exploration:1.0-
-
Prepare docker image in a repository
Create a repository by the instruction and execute the following commands:
./gradlew clean build
docker build -t <your_username>/<your_repository_name>:1.0 .
docker push <your_username>/<your_repository_name>:1.0
- Generate public key and private key to ssh to the EC2 instance.
Put the keys into terraform directory. Public key has to be named
id_rsa.pub
ssh-keygen -t rsa
- Configure AWS CLI to interact with AWS.
More information is here.
aws configure
-
Deploy the app
Open terraform directory in a terminal and run the following commands:
terraform init
terraform plan
terraform apply
To open the app use public IP assigned to the EC2 instance.
For destroying:terraform destroy
Command example for connecting to the instance using SSH:
ssh -i "private_key_path" ec2-user@ec2-34-242-152-56.eu-west-1.compute.amazonaws.com -