This is a full example of deploy a Nginx load balancer for a multi instance web app.
More than that, there is everything to deploy the service from GitHub Actions.
GitHub Actions: https://github.com/alex-piccione/learning.Docker/actions AWS Elastic Container Repository: test-api-service
This is the local root path used for local tests:
cd /d/Programming/Docker\ and\ Kubernetes/learning.Docker/examples/nginx\ api\ devops/
cd "D:\Programming\Docker and Kubernetes\learning.Docker\examples\nginx api devops"
Some setup on AWS, GitHub and the host machine as to be done in advance.
An AWS role with ECR permissions is required.
The AWS role has to be set on the host machine too.
An SSH key as to be set on the host machine.
The API service is a Nodejs application.
There is a GitHub action that create a Docker image and publish it to AWS ECR.
It requires the AWS credentials of a role that has thye right permission for AWS ECR.
It requires ECR already having the containers in the registry.
There is a docker compose file in the devop folder that run the containers.
- Able to run the API service locally
- README contains the command(s) to start the service locally
- API Service should expose /api/info endpoint that return the version
- Bash command to copy secrets/configuration/scripts file to host server
- GitHub action to create images and publish on some Docker image repository
- "deploy api-service.yml"
- "deploy api-service-nginx.yml"
- API service image
- Nginx image
- Setup instructions to prepare server
- Documented
- Setup tested
- Setup Nginx to run both the containers
- ...
- GitHub action to upate and start containers
- test: when removing containers on docker, it will recreate them
- test: when update version, it will show up new version
- GitHub action to update deploy version
- test: after deploy, the services are updated with new version
- Docker Compose
- API service
- Nginx
- Local version to be run locally
- SSH
- Domain
Api server uses secrets from a configuration file.
The configuration file path and server port is passed through Environment variables, see api service/config.js.
Go to local root path.
sh cd "api service" yarn install
-
In local NodejS Go to local root path (currently /examples/nginx api devops/). run:
./devop/start-api.sh
-
Docker compose
docker compose -f devop/compose.local.yml up --build
api service/README.md contains instructions to use the service.
Copy the config file on the server:
scp "/d/secrets/api-service.secrets.json" $user@${server_ip}:/devop/conf/api-service/secrets.json
Install Docker Compose on the server.
(Ubuntu):
sudo apt-get update
sudo apt-get install docker-compose-plugin
check with: docker-compose version
From local root:
docker compose -f compose.local.yml up -d --build
check with
docker ps
Host file structure (obsolete)
/devop
/config
/api_service/conf.json
/data
/api_service_mongodb
/logs
/api_service/(log files)
/scripts
/api_service
Certificate?
deploy api-service image.yml