- GO 1.21+
- Git 2.23.0+
- GNU Make 3.81+
- Docker 20.10.5+
- Nodejs 15.14.0+ & NPM 7.9.0+ (for swagger UI and login UI)
- [Optional] Maven 3.6.0+ (for webjars dependencies)
- Access to any required private Repo via
git@
andid_rsa
is properly set - GO environment variables such as
$GOPATH
and$GOBIN
are properly set
lanai-cli
is a command line tool to help with common build/code generation/git tasks.
make init-cli [CLI_TAG=git_brand_or_tag]
Where the CLI_TAG
is supported and optional for Services.
It typically should match the branch/version of github.com/cisco-open/go-lanai
CI/CD operations are done via GNU Make with help of lanai-cli
and Makefile-Generated
Regardless CI/CD scenarios, CI/CD operators typically need to provide following variables to make
command:
The GO Semantic Version without leading "v".
Example: VERSION=4.0.0-40
, VERSION=4.0.0-RC.1
Default Value: 0.0.0-SNAPSHOT
This variable is REQUIRED in all CI/CD targets unless specified explicitly
Private Modules' path and branch/version which the current project depends on, in format of private.url/path/to/module@branch_or_tag
.
Multiple modules are separated by ","
"Private Module" means extra modules that are not public and is developed/released by same team and are under rapid development.
Example: PRIVATE_MODS=private.url/path/to/module@my_feature_branch
or PRIVATE_MODS=private.url/path/to/module@@v4.0.0-50
Default Value: empty string.
This variable is required in many CI/CD targets if your project has such dependencies
In case go.mod
or other changes (e.g. generated source code) need to be merged back to develop branch, this is required.
Example: SRC_BRANCH=develop
Default Value: empty string
By not providing this variable, "merging back" step is skipped in all applicable scenarios
Note: More information could be found in generated
Makefile-Generated
file
During the process of CI/CD operations, make
targets would modify go.mod
files or generate additional source code.
To track those changes, make
targets would create some local commits and tags as savepoints. Those savepoints/tags
is also known as Marks
.
lanai-cli git
sub-commands provide some useful operations around Marks
.
During the process, all make
targets guarantee following behaviors:
- Git worktree never switch branch/tag
- Git
HEAD
doesn't change. i.e. it always points to the commit at which the process is started
If the process is successful, all make
targets also guarantee following:
- All changes during the process are un-staged
Note: the Git local Worktree should be discarded after use.
Applicable to github.com/cisco-open/go-lanai
Command:
make init
make verify
Variables: VERSION
is not required and PRIVATE_MODS
is not typically required
Do:
- When
PRIVATE_MODS
is provided,go.mod
is updated accordingly - run
generate
,test
andbuild
on packages - coverage report saved to
dist
- code analysis
Command:
make init
make dist VERSION=4.0.0-20
make publish VERSION=4.0.0-20
Variables:
PRIVATE_MODS
not typically requiredSRC_BRANCH
specify if merging changes back to branch is required. Typically, not required for Nightly Build
Do:
- When
PRIVATE_MODS
is provided,go.mod
is updated accordingly - run
generate
,test
andbuild
on packages - ready-to-distribute source code is tagged as
v$VERSION
in Git - the git tag is pushed to remote
This operation is typically performed on previously released Git Tag
Command:
make init
make redist VERSION=4.0.0
make publish VERSION=4.0.0
Variables: PRIVATE_MODS
not required
Do:
- All files are used as-is
- NO
generate
,test
orbuild
- current Git worktree is re-tagged as
v$VERSION
in Git - the git tag is pushed to remote
During development cycle, if service depends on any other module that's being developed in parallel, PRIVATE_MODS
can be used to support it.
For example, service is being developed in develop (or feature) branch, the dependent module is being developed in develop (or feature) branch as well.
Service may have a "replace" directive that points to a local checked out version of the dependent module to help facilitate develop.
During most CI/CD scenarios, the make
target would attempt to "fix" go.mod
and go.sum
by dropping replace
directive
and update corresponding dependency versions.
Command:
make init CLI_TAG=feature/branch
make verify PRIVATE_MODS=private.url/path/to/module@my_feature_branch
Variables:
CLI_TAG
required and should match thePRIVATE_MODS
VERSION
is not requiredPRIVATE_MODS
is required if the PR only works on particular branch of go-lanai
Do:
go.mod
'srequire
section is updated according toPRIVATE_MODS
. Result marked astmp/0.0.0-SNAPSHOT/update-deps
go.mod
'sreplace
is dropped. Result marked astmp/0.0.0-SNAPSHOT/drop-replace
- run
generate
,test
andbuild
on packages - coverage report saved to
dist
- code analysis
Command:
make init CLI_TAG=4.0.0-90
make dist VERSION=4.0.0-20 PRIVATE_MODS=private.url/path/to/module@my_feature_branch@v4.0.0-90 #SRC_BRANCH=any_branch
make publish VERSION=4.0.0-20 DOCKER_REPO=dockerhub.url/my_docker_repository
Variables:
CLI_TAG
required and should match thePRIVATE_MODS
DOCKER_REPO
required for publishSRC_BRANCH
specify if merging changes back to branch is required. Typically, not required for Nightly Build
Do:
go.mod
'srequire
section is updated according toPRIVATE_MODS
. Result marked astmp/$VERSION/update-deps
go.mod
'sreplace
is dropped. Result marked astmp/$VERSION/drop-replace
- run
generate
andtest
on packages - build Docker image and tag as
$VERSION
- ready-to-distribute source code (marked as
tmp/$VERSION/drop-replace
) is tagged asv$VERSION
in Git - the git tag is pushed to remote (publish)
- the Docker image is pushed to Docker repository (publish)
This operation is typically performed on previously released Git Tag.
Because build-info or manifests are built into executables, when promoting one version to another, the executables requires re-build.
Command:
make init
make redist VERSION=4.0.0
make publish VERSION=4.0.0 DOCKER_REPO=dockerhub.url/my_docker_repository
Variables:
PRIVATE_MODS
not requiredDOCKER_REPO
required for publish
Do:
- All files are used as-is
- NO
generate
ortest
- Docker image is rebuilt and tagged as
$VERSION
- current Git worktree is re-tagged as
v$VERSION
in Git - the git tag is pushed to remote (publish)
- the Docker image is pushed to Docker repository (publish)
When Service is being distributed/built, the general CICD process is below:
-
Create a local temporary branch for build.
-
Update go.mod file so that the dependency on go-lanai points to the latest from the matching go-lanai branch or a given go-lanai tag.
-
Create a commit (commit A). This commit has go.mod updated. But this go.mod may still have the replace directive. This commit can be used if we want to merge the update back to the working branch.
-
If there's a "replace" directive for go-lanai, drop it from go.mod.
-
Create a commit (commit B). This commit has the go.mod that will be used exactly for build. This commit is going to be used to tag the build.
-
Generate and test.
-
Build docker image.
-
If step 6 and 7 are successful. Tag commit B for this build and push the tag.
-
Optionally merge commit A back into main branch.