Search
⌃K

Env Sync Init

In some cases, a developer using Env Sync will need to run a different command after a given container is rebuilt and deployed than what is defined in the Dockerfile CMD or the K8s Deployment.
For example, if JS requirements have been updated, calling yarn start may be required to update your JS dependencies. This is possible with Velocity's Env Sync Init feature.
To run a non-default command at container restart, such as yarn start, you can do so by adding the following to your .velocity.yaml configuration file's sync.command:
version: 1
services:
analytics:
sync:
command: sh # Override the container command with 'sh -c yarn start'
args:
- -c
- yarn start
With this in place, you can run:
env sync -s analytics
And when a code change is detected, the analytics Velocity Service will restart with the non-default command sh -c yarn start.
To visualize the effective change, take a look at the following manifests. The "Original manifest" can be deployed to a Velocity Environment, and with the above snippet added to your .velocity.yaml, each time the container is rebuilt by Env Sync, it will behave as if the second manifest is being deployed.
Original manifest
Command overridden with Env Sync Init
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
command: ["sh"]
args: ["-c", "yarn start"]
ports:
- containerPort: 80

Next Steps: