Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Universal CI/CD pipelines.

License

NotificationsYou must be signed in to change notification settings

czetech/lightdevops

Repository files navigation

LightDevOps is a universal GitLab CI/CD pipeline as an easier alternative toGitLab's Auto DevOps. It automatically builds, tests and deploys the applicationto the Kubernetes cluster, only a Dockerfile and a Helm chart is needed.

Quickstart

In the Gitlab project, assuming that the Dockerfile is in the repository, Helmchart is in the./chart directory and theKubernetes clusteris also connected.

InSettings ->CI/CD -> underGeneral pipelines tab, set the path to theCI/CD configuration file:

https://lightdevops.cze.tech/cicd/gitlab-kube-BA-TA-DA.yaml

InSettings ->Repository -> underDeploy tokens tab,create a token with namegitlab-deploy-token and atleastread_registry scope.

Optionally set variableTEST_UNIT_COMMAND with docker image command that runsunit tests.

The next commit creates a pipeline that builds, tests and (in the case of thedefault branch) deploys the application to the Kubernetes cluster. To deploy onthe manual trigger, useDM instead ofDA in the URL.

Customization

Customization is done by CI/CD variables.

Environment

For an explanation of working with environments, seeEnvironments.

NameTypeDescriptionDefault value
ENVIRONMENT_PROD_NAMEVariableProduction environment nameprod
ENVIRONMENT_STAG_NAMEVariableStaging environment namestag
ENVIRONMENT_<0_to_9>_NAMEVariableAdditional environment namesNone

Build

IfBUILD_ENVIRONMENTS is set totrue, all other variables are withinthe scope for the environment.

NameTypeDescriptionDefault value
BUILD_ENVIRONMENTSVariabletrue to create build jobs for individual environments (case-insensitive)None
BUILD_ENABLEDVariableauto to create build job,manual to runs it on the manual trigger (case-insensitive)Depend onvariant
BUILD_FILE_CONTENT_<name>FileAdd a file with the given content to the repository before building,<name> can be any custom nameNone
BUILD_FILE_PATH_<name>VariableThe relative path within the repository to place corresponding file by<name>None
DOCKER_PATHVariableThe relative path to the build's context.
DOCKER_FILEVariableThe relative path to the Dockerfile within the repositoryDocker's default (Dockerfile)
DOCKER_FILEFileDockerfile (if the bundled Dockerfile is not to be used)None
DOCKER_ARG_<name>VariableSet Docker's build-time variable<name> (docker --build-arg<name>=VALUE)None

Test

IfBUILD_ENVIRONMENTS is set totrue, all variables except forTEST_PRECOMMIT_ENABLEDare withinthe scope for the environment.

NameTypeDescriptionDefault value
TEST_ENABLEDVariableauto to create test jobs,manual to run them on the manual trigger (case-insensitive, test command for corresponding test must also be set)Depend onvariant
TEST_UNIT_COMMANDVariableDocker image command to run unit testsNone
TEST_PRECOMMIT_ENABLEDVariabletrue to enablepre-commit test,manual to run it on the manual trigger (case-insensitive, overwritesTEST_ENABLED)None
TEST_PRECOMMIT_FILEVariableThe relative path topre-commit configuration file within the repository.pre-commit-config.yaml
TEST_<0_to_9>_COMMANDVariableDocker image command to run another testsNone

Deploy and clean

All variables are withinthe scope for the environment.

NameTypeDescriptionDefault value
DEPLOY_ENABLEDVariableauto to create deploy jobs,manual to run them on the manual trigger (case-insensitive)Depend onvariant
DEPLOY_URLVariableURL for an environmentNone
KUBE_NAMESPACEVariableKubernetes namespace to deployGitLab's default (<project_name>-<project_id>-<environment>)
HELM_VALUES_<name>VariableHelm values URL,<name> can be any custom nameNone
HELM_VALUES_<name>FileHelm values in YAML format,<name> can be any custom nameNone
HELM_SET_<name>VariableHelm values in key1=val1,key2=val2,... format,<name> can be any custom nameNone
HELM_SETSTRING_<name>VariableHelm STRING values in key1=val1,key2=val2,... format,<name> can be any custom nameNone
HELM_SETFILE_CONTENT_<name>FileHelm value from the given content,<name> can be any custom nameNone
HELM_SETFILE_KEY_<name>VariableHelm key to value by<name>None
HELM_CHARTVariableHelm chart path within the repository or chart name ifHELM_REPO is setchart
HELM_REPOVariableHelm chart repository URL (if the bundled chart is not to be used)None
HELM_USERNAMEVariableHelm chart repository usernameNone
HELM_PASSWORDVariableHelm chart repository passwordNone
HELM_KEY_REPOSITORYVariableHelm chart key to set image repositoryimage.repository
HELM_KEY_TAGVariableHelm chart key to set image tagimage.tag
HELM_KEY_SECRETVariableHelm chart key to set registry secret nameimagePullSecrets[0].name
HELM_DEBUGVariabletrue to enable verbose Helm output and disable atomic flag (case-insensitive)None

Variants

There are variants which define default values forvariablesBUILD_ENABLED,TEST_ENABLED andDEPLOY_ENABLED defined by letters infilename of CI/CD configuration file. Base variant without default values is:

gitlab-kube.yaml

and variant with enabled automatic build is:

gitlab-kube-BA.yaml

All available variants:

VariantVariableDefault value
-BABUILD_ENABLEDauto
-BMBUILD_ENABLEDmanual
-Bx-TATEST_ENABLEDauto
-Bx-TMTEST_ENABLEDmanual
-Bx-Tx-DADEPLOY_ENABLEDauto
-Bx-Tx-DMDEPLOY_ENABLEDmanual

It is not possible to define a default value for the next stage without theprevious one, e.g. forTEST_ENABLED withoutBUILD_ENABLED.

Environments

There are two predefined environments,prod as a production environment andstag as a staging environment. ThevariablesENVIRONMENT_<0_to_9>_NAME can be used to define another 10 environments.

Deployment jobs are created for all defined environments. Creating a deploymentjob for certain environment only, e.g. production environment, is possible bysettingDEPLOY_ENABLED only forprod environment. In the case of the variantwith enabled deployment by default, it is possible to setDEPLOY_ENABLED withthe valuefalse (or anything instead ofauto andmanual) forstagenvironment.

The usual setup is automatic deployment to the staging environment and manual tothe production environment so it is possible to use the-BA-TA-DMvariant and setDEPLOY_ENABLED toauto forstag environment.

WithBUILD_ENVIRONMENTS it is possible to create separate build and test jobsfor each environment. This can be used when the environment settings aredirectly in the builded image (e.g. PWA or mobile applications).

Helm chart requirements

Some values must be possible to set in the Helm chart, but these are standardconventions, so it is assumed that the chart does not need to be modified. Ifnecessary, it is possible to change keys that set these values with CI/CDvariables.

DescriptionDefault valueVariable
Image repositoryimage.repositoryHELM_KEY_REPOSITORY
Image tagimage.tagHELM_KEY_TAG
Registry secret (imagePullSecrets of a pod)imagePullSecrets[0].nameHELM_KEY_SECRET

Troubleshooting

  • When the deploy job failed witherror: You must be logged in to the server (Unauthorized) it is necessary inthe affected GitLab managed cluster, underAdvanced settings tab, clickClear cluster cache.

Build this application

The application itself is a static web page where the CI/CD pipelines are in thecicd directory.

Build from code

Requirements:

Build is done with:

make

then the output is in the./build/web directory.

The Dockerfile and Helm chart are also part of this repository so it can beeasily build and deployed to Kubernetes (e.g. from GitLab by the LightDevOpspipeline itself).

Run from Docker Hub

Run the image from Docker Hub:

docker run -p 80:80 czetech/lightdevops

Install to Kubernetes using Helm

Setup Helm repository:

helm repo add czetech https://charts.cze.tech/

Install Helm chart:

helm install lightdevops czetech/lightdevops \  --set ingress.enabled=true \  --set ingress.hosts[0]=<ingress-host>

see thechart for more options.

Source code

The source code is available athttps://github.com/czetech/lightdevops.


[8]ページ先頭

©2009-2025 Movatter.jp