This GitHub Actions workflow(packerBuild.yml) automates the building and deployment process of a Packer image for a Maven-based Java web application on Google Cloud Platform (GCP). Upon merging pull requests into the main
branch, the workflow triggers a series of steps to ensure a seamless deployment pipeline.
The workflow initiates upon the merging of pull requests into the main
branch, triggering an automated deployment pipeline. Initially, essential dependencies including Maven, PostgreSQL, and Packer are installed on the designated Ubuntu environment. Additionally, environment variables containing sensitive information such as database credentials and GCP metadata are configured, laying the foundation for secure and efficient deployment.
With the environment set up, the workflow proceeds to execute integration and unit tests using Maven, validating the integrity and functionality of the Java web application. Following successful testing, Packer configuration files are initialized, formatted, and validated to ensure consistency and adherence to best practices. These meticulous preparations pave the way for the subsequent building and deployment stages.
The workflow enters the core phase of image building and deployment on Google Cloud Platform. Leveraging Packer, the Java application is encapsulated into a custom image, tailored to the specified requirements and configurations. The built image is then seamlessly deployed to GCP, where it forms the foundation for scalable and resilient application instances.
As the deployment progresses, the workflow continuously monitors the status of the GCP instance group manager, ensuring that the version target is reached. This meticulous monitoring ensures that the deployment is completed successfully, minimizing downtime and disruptions. Upon reaching the version target, the deployment pipeline concludes, marking a successful iteration of the build and deployment process.
packer/
: Directory containing Packer configuration files for immutable image build.systemd/
: Directory containing systemd daemon configuration files for the application startup.target/web-app-0.0.1-SNAPSHOT.jar
: Built JAR file of the Maven project.opsagent/config.yaml
: Configuration file for google ops-agent cloud observability..env
: Environment file containing database credentials.
- Configure necessary secrets in organization GitHub repository settings, including database credentials from terraform infra, GCP credentials, and other environment variables referenced in the workflow.
- Merge pull requests into the
main
branch to trigger the workflow. - Monitor the workflow execution and check the GCP Console for deployment status.
-
Clone the repository:
git clone https://github.com/cloudapp6225/webapp.git
-
Install postgresql server
sudo apt install -y postgresql postgresql-contrib
-
Navigate to the project
cd webapp/
-
Build project
mvn clean install
-
Run Locally
mvn spring-boot:run
{
id: string($uuid)
first_name: string
last_name: string
password: string($password)
username: string($email)
account_created: string($date-time)
account_updated: string($date-time)
}
- Postman client install on your machine
Create a new User
{
"first_name": "Jane",
"last_name": "Doe",
"password": "skdjfhskdfjhg",
"username": "jane.doe@example.com"
}
Get a user by passing username and password in basic authentication header.
Update user details by providing authentication headers.
$ packer init ./packer/.
$ packer fmt ./packer/.
$ packer validate -var 'project_id=dev-gcp-project-1' -var 'source_jar=./target/web-app-0.0.1-SNAPSHOT.jar' -var 'source_env=./.env' -var 'source_systemd=./systemd/webapp.service' ./packer/.
$ packer build -var 'project_id=dev-gcp-project-1' -var 'source_jar=./target/web-app-0.0.1-SNAPSHOT.jar' -var 'source_env=./.env' -var 'source_systemd=./systemd/webapp.service' ./packer/.