This is my github workflow code
name: Test
on:
push:
branches: [ uat ]
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build compose containers
run: |
cp .envs/.local.example .envs/.local
docker-compose -f local.yml build web
docker-compose -f local.yml build postgres
docker-compose -f local.yml build celeryworker
docker-compose -f local.yml build redis
I am able to do it manually, but I want to know how to do it automatically.
In my docker compose file I have also given restart=always
.
2
Answers
It might be a simple syntax issue.
See "Using activity types and filters with multiple events":
The "
array [ xx, yy ]
" syntax is more for eventtypes:
for instance, not forbranches:
.Adding “restart=always” in docker compose file means container will get restarted only when container is stopped or exited.
You can try below options which could help in meeting your requirements.
Option 1:Using nodemon
You can make use of nodemon to automatically restart the node server when code is changed . Before that install nodemon in your docker image and make sure it is present.
Refer the below URL to install nodemon and then change your CMD in Dockerfile:
https://www.npmjs.com/package/nodemon
CMD ["nodemon", "–exec", "npm", "run", "docker-start"]
This is reload your nodejs application whenever codes are changed.
Option 2:Restart Policy in Docker Compose Swarm Mode
The following implementation only works in Docker Compose v3, which introduces the deploy key-value pair in the configuration. Below we can find the different properties to further expand the configuration for restart policies in swarm mode:
window
Let’s define our restart policies. First, we must make sure we’re using Docker Compose v3 by changing the version property:
Once we change the version, we can add the restart_policy property to our services. Similar to the previous section, our message-server container will always restart automatically by providing the any value in the condition:
Similarly, we’ll add an on-failure restart policy to the product-server:
Also, the restart policies in both services include the additional configuration metadata that makes the policies a more robust restart strategy for the containers.
https://www.baeldung.com/ops/docker-compose-restart-policies#restart-policy-in-docker-compose-swarm-mode