forked from nolus-protocol/nolus-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
158 lines (144 loc) · 4.62 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
include:
- '.cicd/kaniko.yml'
- '.cicd/go-build.yml'
- '.cicd/go-verify.yml'
- '.cicd/go-test-abstract.yml'
- '.cicd/go-test.yml'
- '.cicd/go-scheduled-test.yml'
stages:
- prep
- verify
- build
- test
- deploy
variables:
CI_OCI_REGISTRY: "public.ecr.aws/nolus"
AWS_REGISTRY_ID: "013603813222"
AWS_DEV_INSTANCE_ID: "i-0307d4bb453d880f3"
ARTIFACT_BUCKET: "nolus-artifact-bucket"
# https://github.com/GoogleContainerTools/kaniko/issues/1542#issuecomment-853929795
container: "docker"
ARTIFACT_BIN: "nolus.tar.gz"
ARTIFACT_SCRIPTS: "scripts.tar.gz"
# TODO consider determining the last one dynamically from the GitLab API
CONTRACTS_VERSION: "v0.2.7"
CONTRACTS_DIR: "artifacts"
NOLUS_BUILDER_REPO: "builder"
NOLUS_BUILDER_TAG: "0.7"
NOLUS_BUILDER_IMAGE: "${CI_OCI_REGISTRY}/${NOLUS_BUILDER_REPO}:${NOLUS_BUILDER_TAG}"
NOLUS_NODE_REPO: "node"
NOLUS_NODE_TAG: "${CI_COMMIT_TAG}"
NOLUS_NODE_IMAGE: "${CI_OCI_REGISTRY}/${NOLUS_NODE_REPO}:${NOLUS_NODE_TAG}"
prep-version:check:
stage: prep
script:
- if [[ $CI_COMMIT_REF_PROTECTED == "true" ]] && [[ -n "$CI_COMMIT_TAG" ]] ;
then
echo "BUILD_NOLUS_VERSION=true" >> build_version.env ;
else
echo "NOLUS_IMAGE_EXIST=true" >> build_version.env ;
fi
artifacts:
reports:
dotenv: build_version.env
prep-builder:check-exist:
stage: prep
image:
name: amazon/aws-cli
entrypoint: [""]
script:
- if aws ecr-public describe-images --registry-id $AWS_REGISTRY_ID
--repository-name $NOLUS_BUILDER_REPO --region us-east-1
--image-ids=imageTag=$NOLUS_BUILDER_TAG ;
then
echo "NOLUS_BUILDER_EXISTS=true" >> builder_exists.env ;
fi
rules:
- if: '$CI_COMMIT_REF_PROTECTED == "true"'
artifacts:
reports:
dotenv: builder_exists.env
# Builds a builder image only if a new NOLUS_BUILDER_TAG is pushed to a protected git ref.
# Kaniko ref: https://github.com/GoogleContainerTools/kaniko
prep-builder:
stage: prep
needs: ["prep-builder:check-exist"]
extends: .kaniko
variables:
KANIKO_DOCKER_FILE: build/builder_spec
KANIKO_IMAGE: ${NOLUS_BUILDER_IMAGE}
KANIKO_IMAGE_EXISTS: ${NOLUS_BUILDER_EXISTS}
# Builds the binary
build-binary:
stage: build
extends:
- .go-build
script:
- make build
- echo "Ensuring binary is statically linked ..."
&& (file target/release/nolusd | grep "statically linked")
- tar -C target/release/ -czvf $ARTIFACT_BIN .
artifacts:
name: "nolusd-$CI_COMMIT_REF_SLUG"
paths:
- $ARTIFACT_BIN
test-fuzzer:on-schedule:
extends: .go-scheduled-test
script:
- make fuzz
test-unit-cosmos:on-schedule:
extends: .go-scheduled-test
script:
- make test-unit-cosmos
# Deploy a dev network when a new version is being built
prep-deploy:
stage: deploy
needs: ["prep-version:check"]
script:
- echo "BUILD_NOLUS_VERSION=$BUILD_NOLUS_VERSION"
- if [[ $BUILD_NOLUS_VERSION == "true" ]] ;
then
tar -czvf $ARTIFACT_SCRIPTS scripts/remote scripts/common ;
else
echo "Skip preparation for deploy since this is not a new version build" ;
fi
artifacts:
name: "scripts-$CI_COMMIT_REF_SLUG"
paths:
- $ARTIFACT_SCRIPTS
# duplicate 'rules' due to https://gitlab.com/gitlab-org/gitlab/-/issues/351794
setup-dev-network:
stage: deploy
needs: ["build-binary","prep-deploy","prep-version:check"]
image:
name: amazon/aws-cli
entrypoint: [ "" ]
variables:
ACCOUNTS_DIR: accounts
CONTRACTS_INFO_FILE: "contracts-info.json"
script:
- echo "BUILD_NOLUS_VERSION=$BUILD_NOLUS_VERSION"
- if [[ $BUILD_NOLUS_VERSION == "true" ]] ;
then
set -euox pipefail ;
yum install -y tar gzip unzip jq ;
tar -xvf $ARTIFACT_BIN ;
export PATH="$(pwd)":$PATH ;
./.cicd/download_wasm.sh $CONTRACTS_VERSION ;
./scripts/init-dev-network.sh --artifact-bin $ARTIFACT_BIN --artifact-scripts $ARTIFACT_SCRIPTS
--chain-id nolus-dev-1 -v 3 --validator-accounts-dir "$ACCOUNTS_DIR"
--wasm-script-path "artifacts" --wasm-code-path "artifacts"
--contracts-owner-addr "$SMART_CONTRACTS_ADMIN_ADDR"
--treasury-nls-u128 "1000000000000"
--faucet-mnemonic "$FAUCET_MNEMONIC_DEV"
--faucet-tokens "$FAUCET_TOKENS_DEV"
--lpp-native "$STABLE_TICKER_DEV"
--contracts-info-file $CONTRACTS_INFO_FILE ;
else
echo "Skip preparation for deploy since this is not a new version build" ;
fi
artifacts:
name: "dev-net-data-$CI_COMMIT_REF_SLUG"
paths:
- $ACCOUNTS_DIR
- $CONTRACTS_INFO_FILE