From 8bbd8fe249dfa4f8267a087ea0ea25f46cec21c0 Mon Sep 17 00:00:00 2001
From: Pavel Vetokhin
Date: Sun, 18 Feb 2024 13:23:22 +0300
Subject: [PATCH] Use external network
---
.github/actions/setup-gear/action.yaml | 1 +
.github/workflows/beyond-doubt.yaml | 2 +-
baker/ansible/tasks/product/test.yaml | 6 ++++++
stack/product/compose.j2 | 30 ++++++++++++++++----------
4 files changed, 27 insertions(+), 12 deletions(-)
diff --git a/.github/actions/setup-gear/action.yaml b/.github/actions/setup-gear/action.yaml
index 3d7ef15b..1af9d006 100644
--- a/.github/actions/setup-gear/action.yaml
+++ b/.github/actions/setup-gear/action.yaml
@@ -17,6 +17,7 @@ runs:
sudo sed -i -e "1i runner:$(getent group docker | cut -d: -f3):1" /etc/subgid
sudo sed -i -e "1i runner:$(id -u):1" /etc/subuid
sudo systemctl restart docker
+ docker network create gear
- uses: docker/setup-buildx-action@v3.0.0
- uses: docker/build-push-action@v5.1.0
with:
diff --git a/.github/workflows/beyond-doubt.yaml b/.github/workflows/beyond-doubt.yaml
index c08c12e5..61393a32 100644
--- a/.github/workflows/beyond-doubt.yaml
+++ b/.github/workflows/beyond-doubt.yaml
@@ -156,10 +156,10 @@ jobs:
- name: Run ansible-playbook stacks.yaml -t test
run: >-
docker run --rm
+ --network gear
--volume $(pwd):$(pwd)
--volume ~/.m2:/root/.m2
--volume /var/run/docker.sock:/var/run/docker.sock
- --network bezmen_product_network
--workdir $(pwd)/baker/ansible
${{ env.IMAGE_NAME }}:${{ matrix.env.dev }}
ansible-playbook stacks.yaml -t test
diff --git a/baker/ansible/tasks/product/test.yaml b/baker/ansible/tasks/product/test.yaml
index 06b263e1..0538730d 100644
--- a/baker/ansible/tasks/product/test.yaml
+++ b/baker/ansible/tasks/product/test.yaml
@@ -5,6 +5,12 @@
changed_when: false
when: hostvars.db.image_status|default({}) is changed
+- name: Create network
+ ansible.builtin.shell:
+ cmd: docker network inspect gear || docker network create gear
+ strip_empty_ends: false
+ changed_when: false
+
- name: Create stand
ansible.builtin.command:
cmd: >-
diff --git a/stack/product/compose.j2 b/stack/product/compose.j2
index 669c1ca8..bc5c6113 100644
--- a/stack/product/compose.j2
+++ b/stack/product/compose.j2
@@ -1,10 +1,14 @@
name: {{ product.name }}
networks:
- product_network:
+ product:
+ name: product
+ gear:
+ name: gear
+ external: true
configs:
- stack_config:
+ product_config:
file: ./{{ product.config.file_name }}
{% set storage = product.storages[ops[opsenv].storage.vendor]|combine(ops[opsenv].storage) %}
@@ -12,6 +16,9 @@ configs:
services:
storage:
image: {{ storage.image }}:{{ storage.version }}-alpine
+ networks:
+ - product
+ - gear
ports:
- 5432:5432
environment:
@@ -22,11 +29,12 @@ services:
interval: 10s
timeout: 5s
retries: 5
- networks:
- - product_network
database:
image: {{ image_ns }}/{{ database.image }}:{{ database.cid }}
+ networks:
+ - product
+ - gear
depends_on:
storage:
condition: service_healthy
@@ -45,12 +53,13 @@ services:
-Ddatabase.name={{ database.name }}
-Downer.username={{ storage.owner.username }}
-Downer.password={{ storage.owner.password }}
- networks:
- - product_network
{% for schema in product.schemas[storage.vendor] %}
{{ schema.name }}:
image: {{ image_ns }}/{{ database.image }}:{{ database.cid }}
+ networks:
+ - product
+ - gear
depends_on:
database:
condition: service_completed_successfully
@@ -66,18 +75,19 @@ services:
--password={{ storage.owner.password }}
update
-Dschema.name={{ schema.name }}
- networks:
- - product_network
{% endfor %}
{% set apps = product.apps[ops[opsenv].app.lang]|selectattr('service', 'in', usages[purpose].apps) %}
{% for app in apps %}
{{ app.service }}:
image: {{ image_ns }}/{{ app.image }}:{{ hostvars.app.image_tags[app.binary] }}
+ networks:
+ - product
+ - gear
ports:
- 8080:8080
configs:
- - source: stack_config
+ - source: product_config
target: /home/app/{{ product.config.file_name }}
command: >-
--product.config.mapping.mode={{ product.config.mapping_mode }}
@@ -89,6 +99,4 @@ services:
{% endfor %}
labels:
image.key: {{ app.image }}
- networks:
- - product_network
{% endfor %}