Skip to content

Commit

Permalink
Cicd/replace test env wuth s3 (#323)
Browse files Browse the repository at this point in the history
* rework pipeline and test envs to s3

Co-authored-by: sostrovskyi <sostrovskyi>
  • Loading branch information
samo3l authored Jan 5, 2023
1 parent a6b51e0 commit 89790b9
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 22 deletions.
58 changes: 58 additions & 0 deletions .ci/Jenkinsfile.deploy-web-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
pipeline {
agent {
node {
label 'jenkins-main'
}
}
parameters {
gitParameter branchFilter: 'origin/(.*)', defaultValue: 'dev', name: 'sha1', type: 'PT_BRANCH', quickFilterEnabled: true
}
stages {
stage('Web: build') {
steps {
script {
env.VERSION = sh script: "cat version.json | jq .version | tr -d '\"\n'", returnStdout: true
currentBuild.displayName = "#${BUILD_NUMBER}_deploy_${VERSION}"
dir('web') {
sh "make build ENV=dev REACT_APP_ISDOCKEREXT=false"
}
}
}
}
stage('Web: deploy') {
steps {
script {
env.BUCKET_NAME = 'app-' + env.VERSION.replaceAll("[^a-zA-Z0-9 ]+","-")
dir('web') {
def status = sh(script: "aws s3api head-bucket --bucket ${BUCKET_NAME}", returnStatus: true)
if (status == 0) {
echo 'Bucket already exists. Just syncing.'
sh "aws s3 sync build/ s3://${BUCKET_NAME}"
} else {
sh """
aws s3api create-bucket --bucket ${BUCKET_NAME} --region eu-west-2 --acl public-read --create-bucket-configuration LocationConstraint=eu-west-2
aws s3 website s3://${BUCKET_NAME} --index-document index.html --error-document error.html
sed 's/BUCKET_NAME/${BUCKET_NAME}/g' ../.ci/s3/policy.json.template > policy.json
aws s3api put-bucket-policy --bucket ${BUCKET_NAME} --policy file://policy.json
aws s3 sync build/ s3://${BUCKET_NAME}
sed "s/BUCKET_NAME/\$BUCKET_NAME/g" ../.ci/nginx/proxy.s3.conf.template >> /opt/nginx/s3-proxy.conf
docker restart nginx-test-app-gosh-sh
"""
}
}
timeout(15) {
waitUntil {
def r = sh script: "sleep 10 && curl -s --retry-connrefused --retry 100 --retry-delay 5 https://${BUCKET_NAME}.gosh.sh > /dev/null", returnStatus: true
return r == 0
}
}
}
}
post {
always {
cleanWs()
}
}
}
}
}
File renamed without changes.
44 changes: 24 additions & 20 deletions .ci/Jenkinsfile.gosh-prepare-rc
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ pipeline {
dir('contracts/multisig') {
// Deploy msig giver for GOSH deployment
sh 'make build-contracts-docker'
sh 'make generate-docker NETWORK=http://local-node'
sh 'make generate-docker NETWORK=http://local-evernode.gosh.sh'
sh '''
tonos-cli -u http://local-node call 0:ece57bcc6c530283becbbd8a3b24d3c5987cdddc3c8b7b33be6e4a6312490415 sendTransaction "{\\"dest\\": \\"$(cat Giver.addr)\\", \\"value\\": 5000000000000000, \\"bounce\\": false}" --abi GiverV2.abi.json --sign GiverV2.keys.json
tonos-cli -u http://local-evernode.gosh.sh call 0:ece57bcc6c530283becbbd8a3b24d3c5987cdddc3c8b7b33be6e4a6312490415 sendTransaction "{\\"dest\\": \\"$(cat Giver.addr)\\", \\"value\\": 5000000000000000, \\"bounce\\": false}" --abi GiverV2.abi.json --sign GiverV2.keys.json
'''
sh 'make deploy-docker EXTRA_DOCKER_ARGS="--network docker-network-for-se"'
}
Expand All @@ -135,33 +135,37 @@ pipeline {
}
stage('Web: deploy') {
agent {
docker {
image 'jenkins-docker-agent:1'
args '-v /var/run/docker.sock:/var/run/docker.sock -v /opt:/opt --group-add docker'
node {
label 'jenkins-main'
}
}
steps {
script {
env.DOCKER_WEB_CONTAINER_NAME = 'gosh-web-' + currentBuild.displayName.replaceAll("[^a-zA-Z0-9 ]+","-")
env.BUCKET_NAME = "app-" + "${BRANCH}_${VERSION}".replaceAll("[^a-zA-Z0-9 ]+","-")
env.REACT_APP_GOSH_ROOTADDR = sh script: "cat contracts/gosh/VersionController.addr | tr -d '\n'", returnStdout: true
env.REACT_APP_GOSH = sh script: "cat contracts/gosh/SystemContract.addr | tr -d '\n'", returnStdout: true
sh """
touch ${DOCKER_WEB_CONTAINER_NAME}.gosh.sh
sed -i '/REACT_APP_GOSH_ROOTADDR =/s/\$/${REACT_APP_GOSH_ROOTADDR}/' web/.env.ci
sed -i '/REACT_APP_GOSH =/s/\$/{"1.0.0": "${REACT_APP_GOSH}"}/' web/.env.ci
mkdir /opt/${DOCKER_WEB_CONTAINER_NAME} && cp -r web /opt/${DOCKER_WEB_CONTAINER_NAME}/web
"""
dir('web') {
sh """
if [ `docker ps | grep -o "gosh-web.*" | wc -l` -gt 1 ]; then docker ps | grep -o "gosh-web.*" | while read -r line ; do echo \$line ; done | sort | docker rm -f `head -n 1`; fi
make run MOUNT_DIR=/opt/${DOCKER_WEB_CONTAINER_NAME}/web ENV=ci REACT_APP_ISDOCKEREXT=false DOCKER_RUN_ARGS='--network test.app.gosh.sh' DOCKER_WEB_CONTAINER_NAME=${DOCKER_WEB_CONTAINER_NAME}
echo 'server_names_hash_bucket_size 1024;' > /opt/nginx/proxy.conf
echo 'server { listen 80 default_server; return 404;}' >> /opt/nginx/proxy.conf
docker ps | grep -o "gosh-web.*" | while read -r line ; do sed "s/GOSH_WEB_VERSION/\$line/g" ../.ci/nginx/proxy.conf.template >> /opt/nginx/proxy.conf; done
docker restart nginx-test-app-gosh-sh
"""
sh "make build ENV=ci REACT_APP_ISDOCKEREXT=false"
def status = sh(script: "aws s3api head-bucket --bucket ${BUCKET_NAME}", returnStatus: true)
if (status == 0) {
echo 'Bucket already exists. Just syncing.'
sh "aws s3 sync build/ s3://${BUCKET_NAME}"
} else {
sh """
aws s3api create-bucket --bucket ${BUCKET_NAME} --region eu-west-2 --acl public-read --create-bucket-configuration LocationConstraint=eu-west-2
aws s3 website s3://${BUCKET_NAME} --index-document index.html --error-document error.html
sed 's/BUCKET_NAME/${BUCKET_NAME}/g' ../.ci/s3/policy.json.template > policy.json
aws s3api put-bucket-policy --bucket ${BUCKET_NAME} --policy file://policy.json
aws s3 sync build/ s3://${BUCKET_NAME}
sed "s/BUCKET_NAME/\$BUCKET_NAME/g" ../.ci/nginx/proxy.s3.conf.template >> /opt/nginx/s3-proxy.conf
docker restart nginx-test-app-gosh-sh
"""
}
}
archiveArtifacts artifacts: "${DOCKER_WEB_CONTAINER_NAME}.gosh.sh*"
}
}
}
Expand All @@ -176,7 +180,7 @@ pipeline {
script {
timeout(15) {
waitUntil {
def r = sh script: "sleep 100 && curl -s --retry-connrefused --retry 100 --retry-delay 5 https://${DOCKER_WEB_CONTAINER_NAME}.gosh.sh > /dev/null", returnStatus: true
def r = sh script: "sleep 10 && curl -s --retry-connrefused --retry 100 --retry-delay 5 https://${BUCKET_NAME}.gosh.sh > /dev/null", returnStatus: true
return r == 0
}
}
Expand All @@ -198,7 +202,7 @@ pipeline {
sh """
mkdir /home/jenkins/bin && cp -r ../git-remote-gosh/git-remote-gosh-amd64 /home/jenkins/bin/git-remote-gosh && chmod +x /home/jenkins/bin/git-remote-gosh
export PATH=/home/jenkins/.everdev/tonos-cli/:/home/jenkins/bin:$PATH
./set-vars.sh http://local-node
./set-vars.sh http://local-evernode.gosh.sh
"""
def files = sh(script: 'ls *.test.sh | grep "[0-9][0-9]-\\+"', returnStdout: true).trim().split('\n')
runParallel items: (files).collect { "${it}" }
Expand Down Expand Up @@ -227,7 +231,7 @@ pipeline {
-e GM_MODE='${tests[i].trim()}' \
-e RUN_NOW=1 \
-e CONFIG_SEED="\$(tonos-cli -j genphrase | jq .phrase | tr -d '\"\n')" \
-e CONFIG_APPURL=https://${DOCKER_WEB_CONTAINER_NAME}.gosh.sh/ \
-e CONFIG_APPURL=https://${BUCKET_NAME}.gosh.sh/ \
-e CONFIG_REDIS_HOST="" \
-v \$(pwd)/config:/home/node/app/config:ro \
-v \$(pwd)/test-errors:/home/node/app/errors \
Expand Down
2 changes: 1 addition & 1 deletion .ci/Jenkinsfile.gosh-release
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pipeline {
}
steps {
script {
build job: 'deploy-web', parameters: [[$class: 'StringParameterValue', name: 'sha1', value: "${TAG}"]]
build job: 'deploy-web-prod', parameters: [[$class: 'StringParameterValue', name: 'sha1', value: "${TAG}"]]
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions .ci/nginx/proxy.conf.template
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
server_names_hash_bucket_size 1024;
server { listen 80 default_server; return 404;}

server {

listen 80;
Expand Down
11 changes: 11 additions & 0 deletions .ci/nginx/proxy.s3.conf.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
server {

listen 80;
server_name BUCKET_NAME.gosh.sh;

location / {
proxy_pass http://BUCKET_NAME.s3-website.eu-west-2.amazonaws.com;
proxy_intercept_errors on;
}

}
15 changes: 15 additions & 0 deletions .ci/s3/policy.json.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicRead",
"Effect": "Allow",
"Principal": "*",
"Action": [
"s3:GetObject",
"s3:GetObjectVersion"
],
"Resource": "arn:aws:s3:::BUCKET_NAME/*"
}
]
}
2 changes: 1 addition & 1 deletion web/.env.ci
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PUBLIC_URL=/
REACT_APP_GOSH_NETWORK = https://vps23.ton.dev
REACT_APP_GOSH_NETWORK = http://local-evernode.gosh.sh
REACT_APP_GOSH_ROOTADDR =
REACT_APP_GOSH =
REACT_APP_IPFS = https://ipfs.network.gosh.sh
Expand Down

0 comments on commit 89790b9

Please sign in to comment.