Currently working on container-based CI/CD, a naive idea for automated deployment is:

  • Print a Git tag from the Git Repo as a mirror tag
  • SSH Remote login to the deployment machine
  • Inject the image Tag into the deployment environment, pull the image, and redeploy

How do I inject image TAG into K8s/Docker-compose?

k8s

Those familiar with K8S know that k8S has a powerful native configuration management tool: the Kustomize tool.

Kustomize simplifies the use of existing applications by customizing application configuration in a template-free manner. Kustomize is now built into Kubectl as apply-k.

Here you can use Kustomize’s edit command to modify the mirror TAG defined in kustomization.yaml:

Here is a simple kustomization.yaml file:

kind: Kustomization namespace: wd resources: - .. / base images: - name: hub.docker.com/eap/website / / original image a newName: hub.docker.com/eap/website newTag: V1.0.7-hotfix5 // Continuously modified tagsCopy the code

During automatic deployment, CI usually imports the Git Tag into the deployment script as an image Tag.

#! /bin/sh cd /home/wd-deploy/localdeploy/wd/overlays/ kustomize edit set image hub.docker.com/eap/website=hub.docker.com/eap/website:${TAG} kustomize build . | kubectl apply -f -Copy the code

Above deployment script: Go to the kustomization.yaml directory, inject the new image Tag into the kustomization.yaml file, and build and apply the new configuration.

docker-compose

The Docker platform doesn’t have a tool that lets you change the image configuration in plain text.

We can modify the image configuration using shell script curves:

Suppose you have a simple docker-comemage. yml file:

version: '3'

services:
    app:
        image: username/app:d7s8f12
        ports:
            - 80:80
Copy the code

Sed -e -i “”s/(.*app:).*/\1$COMMIT/” ‘docker-compose.yml’

Similarly, during automatic deployment, CI imports the Git Tag into the script as a mirror Tag.

#! /bin/sh cd /home/wd-deploy/app/ sed -E -i'' "s/(.*app:).*/\1$COMMIT/" 'docker-compose.yml' docker-compose pull app && docker-compose up -dCopy the code

Above deployment script: Go to the docker-comemess. yml directory, inject the new image Tag into the compose file, pull the image and apply the new configuration.

conclusion

This article describes how to inject image Tag into K8s docker-compose. Because Tag injection is a necessary part of automatic deployment.

This article is just a superficial, naive idea for injection (there are many components in the Devops ecosystem that can do this)

Author: _ Small size armour

Link: www.cnblogs.com/JulianHuang…