Micro services responsible for work with transactions
- Make 4.1
- Docker 1.12
- Docker Compose >= 1.22 - https://docs.docker.com/compose/install/
-
Installing dnsmasq - service start error can appear due to occupied port 53 on the address 127.0.0.53:
sudo apt-get install dnsmasq -
Redirect domain
loto the address of the Docker interface, please issue a command:Domain redirection ‘lo’ to the address of the Docker interface, create
/etc/dnsmasq.d/lofile and pasteinterface=lo interface=docker0 bind-interfaces address=/.lo/172.17.0.1 -
Add the DNS server to your resolver in the file
/etc/systemd/resolved.conf:[Resolve] DNS=127.0.0.1If you have fresh system installations, you can issue a command:
sudo sed -i 's|#DNS=|DNS=127.0.0.1|g' /etc/systemd/resolved.conf -
Start Dnsmasq
sudo systemctl restart dnsmasq -
Enable service startup during system boot
sudo systemctl enable dnsmasq -
Restart resolver
sudo systemctl restart systemd-resolved -
Create a directory:
sudo mkdir -p /etc/systemd/system/docker.service.d -
Docker DNS configuration:
echo "[Service]\nExecStart=\nExecStart=/usr/bin/dockerd -H fd:// --dns 172.17.0.1 --dns 8.8.8.8 --dns 8.8.4.4" | sudo tee /etc/systemd/system/docker.service.d/dns.conf -
Restart the Docker daemon:
sudo systemctl restart docker.service; sudo systemctl daemon-reload -
Run proxy for Docker:
docker run -d -p 172.17.0.1:80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro --name docker-proxy --restart always jwilder/nginx-proxy -
Create networks for the proxy
docker network create proxy -
Add Nginx Proxy to a proxy network:
docker network connect proxy docker-proxy -
Launching the project in the project directory
make first-runor if you already have run themake run
Each project has the environment variable BASE_DOMAIN,
it is set to the default value in the Makefile file, in this project it is trl.financial.lo.
Using addresses from the environment variable BASE_DOMAIN (trl.financial.lo)
you can make a request from a web browser from your computer
or inside any container.
Microservices communicate with each other using a proxy and domain address (Nginx-Proxy), eg:
command:
curl http://financial.lo/expenseResponse:
{"example": "json"}command:
docker run -it --rm ubuntu bash -c 'apt update && apt install curl -y && curl http://financial.lo/expense'Response:
{"example": "json"} sudo systemctl restart dnsmasq.service
With the Docker DNS-get service, you can connect to applications in containers,
using the names of containers in the address
e.g. if you want to integrate your editor with a database in a container,
you can enter the address financial-trl_database_1.docker to connect to the container financial-trl_database_1
-
Create a container with the Docker DNS-gen service:
docker run --detach \ --name dns-gen \ --restart always \ --publish 127.0.0.1:54:53/udp \ --volume /var/run/docker.sock:/var/run/docker.sock \ jderusse/dns-gen
-
Create file
/etc/dnsmasq.d/docker-dns-genand pasteserver=127.0.0.1#54 -
Reset the dnsmasq
sudo systemctl restart dnsmasq.service -
Reset the resolver
sudo systemctl restart systemd-resolved
The .editorconfig file has saved the configuration of code indentation for individual types of text files,
which allows you to automatically configure the editor.
Go to the website editorconfig.org and check if your editor has native support or you need to install the extension.
-
Installing the plugin:
-
PhpStorm: File -> Settings... -> Plugins -> Browse repositories -> Enter in the search engine: EditorConfig.
The editor usually recommends installing a plugin after detecting the
.editorconfigfile.
-
If you have a properly configured environment,
it is enough to issue the make first.run command to run the project
- Another project launch:
make run. - Launching a single Docker service:
make run name=application. - Stopping the project:
make stop. - Stopping one service:
make stop name=application. - Restart project :
make restart. - Restarting a single Docker service:
make restart name=application. - Build a project:
make build. - Build of a single Docker service:
make build name=application. - Scaling services with project restart:
make scale name=application n=3. - Scanning a single service:
make scale.single name=application n=3 - Download Docker images:
make pull. - Rebuild the project:
make rebuild. - List of project container statuses:
make status. - Displaying the generated docker-compose:
make config - Remove project containers:
make remove. - Remove containers for a single Docker service:
make remove name=application. - Removal of containers, images, project volumes:
make destroy. - Examples of command combinations:
make name='webserver application' build runmake name=database stop remove run
- Display of logs captured from containers on live:
make logs
- First launch of the project:
make first.run. - Running the tool console:
make shell - Running the console with tools and tests:
make shell.tests - Rebuilding the project, used when changing the git branch:
make build.all. - Installation of composer packages:
make composer.install. - Update composer packages:
make composer.update. - Performing the migration:
make migrate. - Generating default data to the database:
make seed - Generation of random data to the database:
make seed-random
-
Displaying logs from a container:
docker logs -f container -
Display only errors and hide the log:
docker logs -f container >/dev/null -
Displaying logs, hide errors:
docker logs -f container 2>/dev/null
Environment variables can be found in the .env file.
When you first run the project, the .env.example file is cope to .env.
The .env file is ignored by Git,
If you want to add new environment variables, you should also put them in the .env.example file.
The .env.example file should contain production configuration values,
while local default addresses, to automatically launch the environment.
In the .env file you have environment variables:
-
ENVIROMENT_MODE: - environment modeprod- Very simple production mode.develop- Development environment mode (prod + database on Docker).ci- Environment mode allowed to run on CICD server (develop mode + makefile CI).tools- Environment mode for developers, it has tools (develop mode + tools).
-
USE_BUILD_DOCKER_IMAGES: - Enables setting if you want to use Docker or Dockerfile imagestrue- Set to use Dockerfile and locally built images.false- Set to use Docker images.
After making changes to the environment variables in the .env file,
you must issue the command make build run command.
Declaring used docker images, tags and repository is done using the .docker.images file.
A dynamic environmental has been used, which always includes the path of expanding the production modes and development modes.
Inheritance path:
-
Environment mode
prod- production:- Does not contain databases.
- Contains application containers.
- Mode environment is enabled by setting the environment variable
ENVIROMENT_MODE = prodin the.envfile. - Environment mode is managed the
makefiles / prod.mkfile. - Docker Compose file responsible for the environment mode is
docker-compose.yml.
-
Middle mode
develop- development, production mode + databases in containers:- Is generally intended for development process.
- The environment mode includes bases in containers and application containers.
- Mode environment is enabled by setting the environment variable
ENVIROMENT_MODE = developin the file.env. - The environment mode is managed the
makefiles / develop.mkfile. - Docker Compose file responsible for the environment mode is
docker-compose.yml+docker-compose.develop.yml - If you set
USE_BUILD_DOCKER_IMAGES = truein the.envfile, it will use theDockerfilefiles. Flow Docker Compose:docker-compose.yml+docker-compose.develop.yml(+docker-compose.build.yml) - Please note that, this mode is also used on the CI / CD server.
- In the case of running tests, the flow looks as follows:
docker-compose.yml+docker-compose.develop.yml(+docker-compose.build.yml) (+docker-compose.tests.yml)
-
Environment mode
ci- used on a CI / CD server (continuous integration, continuous deployment)- Mode environment is enabled by setting the environment variable
ENVIROMENT_MODE = ciin the.envfile - The environment mode is managed via the
makefiles / ci.mk.mkfile this file contains the procedures used on the CI / CD server when building the code - Environment mode
cihas a common flow docker-compose like the environment modedevelop:docker-compose.yml+docker-compose.develop.yml(+docker-compose.build.yml) - In the case of running tests, the flow looks as follows:
docker-compose.yml+docker-compose.develop.yml+docker-compose.tools.yml(+docker-compose.build.yml) (+docker-compose.tests.yml)
- Mode environment is enabled by setting the environment variable
-
Environment mode
tools- the right environment for developers, this is thedevelop+ development tools environment- Mode environment is enabled by setting the environment variable
ENVIROMENT_MODE = toolsin the.envfile - The environment mode is managed via the
makefiles / tools.mkfile - After setting
USE_BUILD_DOCKER_IMAGES = truein the.envfile, it will use theDockerfilefiles, and not from already built Docker images. Flow Docker Compose:docker-compose.yml+docker-compose.develop.yml+docker-compose.tools.yml(+docker-compose.build.yml) - In the case of running tests, the flow looks as follows:
docker-compose.yml+docker-compose.develop.yml+docker-compose.tools.yml(+docker-compose.build.yml) (+docker-compose.tests.yml)
- Mode environment is enabled by setting the environment variable
-
Application: financial.lo,
-
Redis commander: redis.financial.lo,
-
PgAdmin: pgadmin.financial.lo,
- email: pgadmin4@pgadmin.org
- hasło: admin
- Restart networking service
sudo systemctl restart network-manager.service - Restart Dnsmasq
sudo systemctl restart dnsmasq.service
- Check resolved DNS
nslookup financial.lo - Check resolv DNS-gen
dig @127.0.0.1 -p 54 financial-trl_webserver_1.docker