Skip to content

Commit

Permalink
Merge pull request #214 from valory-xyz/feature/imrpoved_deployment_w…
Browse files Browse the repository at this point in the history
…ith_ci

improved CI deployment
  • Loading branch information
0xArdi authored Jul 19, 2024
2 parents 274a19e + fe901eb commit 0c4423f
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 3 deletions.
122 changes: 119 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ jobs:
echo "Pushing $DOCKER_USER/oar-$AGENT:$DEFAULT_IMAGE_TAG"
docker push $DOCKER_USER/oar-$AGENT:$VERSION
docker push $DOCKER_USER/oar-$AGENT:$DEFAULT_IMAGE_TAG
deploy-service-on-propel:
name: Deploy service on propel
environment: ${{ fromJSON('[["staging", "staging"], ["production", "shorts_production"]]')[github.event.action == 'released'][endsWith(github.event.release.name, '(shorts)')] }}
deploy_production:
name: Deploy to production
environment: production
if: endsWith(github.event.release.name, '(prod)')
needs:
- "publish-packages"
- "publish-images"
Expand Down Expand Up @@ -149,3 +150,118 @@ jobs:
echo '${{ toJSON(vars) }}' | jq -r 'to_entries|map("export \(.key)=\(.value|tojson)")|.[]' >> github.vars
source github.vars
$CMD service deploy --name '${{ vars.SERVICE_NAME }}' --service-dir $SERVICE_PATH --service-ipfs-hash $IPFS_HASH --ingress-enabled true --keys '${{ vars.SERVICE_KEYS }}' --timeout 320
deploy_staging:
name: Deploy to staging
environment: staging
if: endsWith(github.event.release.name, '(staging)')
needs:
- "publish-packages"
- "publish-images"
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
python-version: ["3.10"]
env:
CMD: "propel -U ${{ vars.PROPEL_BASE_URL }}"
steps:
- uses: actions/checkout@master
- uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-versions }}
- name: Install dependencies
run: |
sudo apt-get update --fix-missing
sudo apt-get autoremove
sudo apt-get autoclean
python -m pip install --upgrade pip
pip install propel-client open-autonomy
- name: Make use proxy instead of actual nlb by dns override
run: |
# for staging
export IP_ADDR=$(dig +short balancer.tcp.propel.staging.autonolas.tech)
echo -e "\n$IP_ADDR\tapp.propel.staging.valory.xyz\n" | sudo tee -a /etc/hosts
# for prod
export IP_ADDR=$(dig +short balancer.tcp.propel.autonolas.tech)
echo -e "\n$IP_ADDR\tapp.propel.valory.xyz\n" | sudo tee -a /etc/hosts
- name: Login to propel
run: |
$CMD login -u '${{ vars.PROPEL_USERNAME }}' -p '${{ secrets.PROPEL_PASSWORD }}'
- name: Do a deployment
run: |
# determine ipfs hash id
export IPFS_HASH=$(jq '.dev | to_entries[] | select(.key | startswith("service"))| .value' -r ./packages/packages.json | head -n1)
export SERVICE_PATH=service_for_propel
# fetch service file and check it published
autonomy init --reset --author ci --ipfs --remote
autonomy fetch $IPFS_HASH --service --alias $SERVICE_PATH
# get env vars from github actions
echo '${{ toJSON(secrets) }}' | jq -r 'to_entries|map("export \(.key)=\(.value|tojson)")|.[]' > github.vars
echo >> github.vars
echo '${{ toJSON(vars) }}' | jq -r 'to_entries|map("export \(.key)=\(.value|tojson)")|.[]' >> github.vars
source github.vars
$CMD service deploy --name '${{ vars.SERVICE_NAME }}' --service-dir $SERVICE_PATH --service-ipfs-hash $IPFS_HASH --ingress-enabled true --keys '${{ vars.SERVICE_KEYS }}' --timeout 320
deploy_shorts:
name: Deploy to shorts
environment: shorts_production
if: endsWith(github.event.release.name, '(shorts)')
needs:
- "publish-packages"
- "publish-images"
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
python-version: ["3.10"]
env:
CMD: "propel -U ${{ vars.PROPEL_BASE_URL }}"
steps:
- uses: actions/checkout@master
- uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-versions }}
- name: Install dependencies
run: |
sudo apt-get update --fix-missing
sudo apt-get autoremove
sudo apt-get autoclean
python -m pip install --upgrade pip
pip install propel-client open-autonomy
- name: Make use proxy instead of actual nlb by dns override
run: |
# for staging
export IP_ADDR=$(dig +short balancer.tcp.propel.staging.autonolas.tech)
echo -e "\n$IP_ADDR\tapp.propel.staging.valory.xyz\n" | sudo tee -a /etc/hosts
# for prod
export IP_ADDR=$(dig +short balancer.tcp.propel.autonolas.tech)
echo -e "\n$IP_ADDR\tapp.propel.valory.xyz\n" | sudo tee -a /etc/hosts
- name: Login to propel
run: |
$CMD login -u '${{ vars.PROPEL_USERNAME }}' -p '${{ secrets.PROPEL_PASSWORD }}'
- name: Do a deployment
run: |
# determine ipfs hash id
export IPFS_HASH=$(jq '.dev | to_entries[] | select(.key | startswith("service"))| .value' -r ./packages/packages.json | head -n1)
export SERVICE_PATH=service_for_propel
# fetch service file and check it published
autonomy init --reset --author ci --ipfs --remote
autonomy fetch $IPFS_HASH --service --alias $SERVICE_PATH
# get env vars from github actions
echo '${{ toJSON(secrets) }}' | jq -r 'to_entries|map("export \(.key)=\(.value|tojson)")|.[]' > github.vars
echo >> github.vars
echo '${{ toJSON(vars) }}' | jq -r 'to_entries|map("export \(.key)=\(.value|tojson)")|.[]' >> github.vars
source github.vars
$CMD service deploy --name '${{ vars.SERVICE_NAME }}' --service-dir $SERVICE_PATH --service-ipfs-hash $IPFS_HASH --ingress-enabled true --keys '${{ vars.SERVICE_KEYS }}' --timeout 320
15 changes: 15 additions & 0 deletions DEPLOYMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# DEPLOYMENT PROCESS

use make release command:
it creates tag, pushes to github and makes release that triggers deployment process
release environment determined by suffix format `(<env_name>)` like `release v0.11 (prod)`

list of environments supported is at release.yaml file

to use gommand you have to install gh command locally, and login with it

`./make_release.sh <VERSION> <ENV_NAME> [OPTIONAL DESCRIPTION]`

example:
`./make_release.sh 0.11 prod 'some description'`

29 changes: 29 additions & 0 deletions make_release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

export VERSION=$1
export ENV=$2
export DESCRIPTION=$3

if [ -z $VERSION ]; then
echo no version
exit 1
fi

if [ -z $ENV ]; then
echo no env
exit 1
fi

export TAG_NAME=release_${VERSION}_${ENV}

echo make tag $TAG_NAME ...
git tag $TAG_NAME
echo push tag $TAG_NAME ...
git push origin $TAG_NAME
echo create release $TAG_NAME ...

if gh release create $TAG_NAME --title "Release $VERSION ($ENV)" --notes "$DESCRIPTION"; then
echo done
else
echo Error!
fi

0 comments on commit 0c4423f

Please sign in to comment.