Skip to content

Commit

Permalink
Merge pull request #11 from Humanitec-DemoOrg/humctl
Browse files Browse the repository at this point in the history
`humctl score deploy`
  • Loading branch information
mathieu-benoit authored Mar 31, 2024
2 parents 272e040 + ba90d3b commit 05cc91d
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 97 deletions.
19 changes: 8 additions & 11 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,16 @@ jobs:
apps: ["cartservice", "checkoutservice", "currencyservice", "emailservice", "frontend", "loadgenerator", "paymentservice", "productcatalogservice", "recommendationservice", "shippingservice"]
runs-on: ubuntu-22.04
env:
SCORE_HUMANITEC_VERSION: 'latest'
HUMCTL_VERSION: '0.19.1'
steps:
- name: checkout code
uses: actions/checkout@v3
- name: install score-humanitec
uses: score-spec/setup-score@v2
- name: install humctl
uses: humanitec/setup-cli-action@v1
with:
file: score-humanitec
token: ${{ secrets.GITHUB_TOKEN }}
version: ${{ env.SCORE_HUMANITEC_VERSION }}
- name: score-humanitec run
version: ${{ env.HUMCTL_VERSION }}
- name: humctl score validate
run: |
score-humanitec run \
--env development \
-f apps/${{ matrix.apps }}/score.yaml \
--extensions apps/${{ matrix.apps }}/humanitec.score.yaml
humctl score validate apps/${{ matrix.apps }}/score.yaml \
--token ${{ secrets.HUMANITEC_TOKEN }} \
--org ${{ secrets.HUMANITEC_ORG }}
2 changes: 1 addition & 1 deletion .github/workflows/frontend-close-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- closed
env:
ENVIRONMENT_ID: pr-${{ github.event.number }}-frontend
HUMCTL_VERSION: '0.12.0'
HUMCTL_VERSION: '0.19.1'
jobs:
job:
runs-on: ubuntu-latest
Expand Down
101 changes: 47 additions & 54 deletions .github/workflows/frontend-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ env:
ENVIRONMENT_TYPE: 'development'
ENVIRONMENT_ID: pr-${{ github.event.number }}-frontend
ENVIRONMENT_NAME: PR-${{ github.event.number }}
SCORE_HUMANITEC_VERSION: 'latest'
HUMCTL_VERSION: '0.12.0'
HUMCTL_VERSION: '0.19.1'
jobs:
job:
runs-on: ubuntu-latest
Expand All @@ -35,64 +34,35 @@ jobs:
-t ${{ env.ENVIRONMENT_TYPE }} \
--from ${{ env.BASE_ENVIRONMENT }} \
|| true
- name: install score-humanitec
uses: score-spec/setup-score@v2
with:
file: score-humanitec
token: ${{ secrets.GITHUB_TOKEN }}
version: ${{ env.SCORE_HUMANITEC_VERSION }}
- name: deploy score-humanitec
- name: humctl score deploy
run: |
score-humanitec delta \
--retry \
--deploy \
HUMANITEC_CLI_ALPHA_FEATURES=score-deploy humctl score deploy \
--deploy-config apps/score.deploy.yaml \
--image ${{ env.IMAGE_NAME }}@${IMAGE_DIGEST} \
--message "$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "${{ github.event.pull_request.commits_url }}?per_page=10" | jq -r .[-1].commit.message)" \
--workload-source-url-prefix "https://github.com/${{ github.repository }}/blob/${{ github.head_ref }}/apps" \
--token ${{ secrets.HUMANITEC_TOKEN }} \
--org ${{ secrets.HUMANITEC_ORG }} \
--app ${{ vars.APP_NAME }} \
--env ${{ env.ENVIRONMENT_ID }} \
-f ${{ env.WORKLOAD_FOLDER }}/score.yaml \
--extensions ${{ env.WORKLOAD_FOLDER }}/humanitec.score.yaml \
--message "$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "${{ github.event.pull_request.commits_url }}?per_page=10" | jq -r .[-1].commit.message)" \
| tee score_output.json
- name: wait for deployment
--wait
- name: build comment message
if: ${{ always() }}
run: |
sleep 1
IS_DONE=false
CURRENT_STATUS=""
while [ "$IS_DONE" = false ]; do
CURRENT_STATUS=$(humctl get deployment . -o json \
DEPLOYMENT_ID=$(humctl get deployment . -o json \
--token ${{ secrets.HUMANITEC_TOKEN }} \
--org ${{ secrets.HUMANITEC_ORG }} \
--app ${{ vars.APP_NAME }} \
--env ${{ env.ENVIRONMENT_ID }} \
| jq -r .status.status)
if [ "$CURRENT_STATUS" = "in progress" ]; then
echo "Deployment still in progress..."
sleep 1
elif [ "$CURRENT_STATUS" = "failed" ]; then
echo "Deployment failed!"
IS_DONE=true
else
echo "Deployment successfully completed!"
IS_DONE=true
fi
done
echo $CURRENT_STATUS
if [ "$CURRENT_STATUS" = "failed" ]; then
exit 1
fi
- name: build comment message
if: ${{ always() }}
run: |
ENV_URL=$(jq -r ".metadata.url" score_output.json)
DEPLOYMENT_ID=$(jq -r ".id" score_output.json)
| jq -r .metadata.id)
ENV_URL="https://app.humanitec.io/orgs/"${{ secrets.HUMANITEC_ORG }}"/apps/"${{ vars.APP_NAME }}"/envs/"${{ env.ENVIRONMENT_ID }}"/deploys/"${DEPLOYMENT_ID}
DOMAINS=$(humctl get active-resources \
--token ${{ secrets.HUMANITEC_TOKEN }} \
--org ${{ secrets.HUMANITEC_ORG }} \
--app ${{ vars.APP_NAME }} \
--env ${{ env.ENVIRONMENT_ID }} -o json \
| jq -r '. | map(. | select(.metadata.type == "dns")) | map((.metadata.res_id | split(".") | .[1]) + ": [" + .status.resource.host + "](https://" + .status.resource.host + ")") | join("\n")')
DEPLOYMENT_ERRORS=$(humctl get deployment-error \
--token ${{ secrets.HUMANITEC_TOKEN }} \
--org ${{ secrets.HUMANITEC_ORG }} \
Expand Down Expand Up @@ -148,16 +118,39 @@ jobs:
echo "" >> pr_message.txt
echo "</details>" >> pr_message.txt
echo "<details><summary>Score Output</summary>" >> pr_message.txt
echo "" >> pr_message.txt
echo "### Score Output:" >> pr_message.txt
echo '```json' >> pr_message.txt
echo "" >> pr_message.txt
cat score_output.json >> pr_message.txt
echo "" >> pr_message.txt
echo '```' >> pr_message.txt
echo "" >> pr_message.txt
echo "</details>" >> pr_message.txt
if [ "$DEPLOYMENT_ERRORS" = "[]" ]; then
echo "<details><summary>Active Resources Usage</summary>" >> pr_message.txt
echo "" >> pr_message.txt
echo "### Active Resources Usage:" >> pr_message.txt
echo '```none' >> pr_message.txt
echo "" >> pr_message.txt
humctl resources active-resource-usage \
--env ${{ env.ENVIRONMENT_ID }} \
--token ${{ secrets.HUMANITEC_TOKEN }} \
--org ${{ secrets.HUMANITEC_ORG }} \
--app ${{ vars.APP_NAME }} >> pr_message.txt
echo "" >> pr_message.txt
echo '```' >> pr_message.txt
echo "" >> pr_message.txt
echo "</details>" >> pr_message.txt
fi
if [ "$DEPLOYMENT_ERRORS" = "[]" ]; then
echo "<details><summary>Resources Graph</summary>" >> pr_message.txt
echo "" >> pr_message.txt
echo "### Resources Graph:" >> pr_message.txt
echo '```none' >> pr_message.txt
echo "" >> pr_message.txt
humctl resources graph \
--env ${{ env.ENVIRONMENT_ID }} \
--token ${{ secrets.HUMANITEC_TOKEN }} \
--org ${{ secrets.HUMANITEC_ORG }} \
--app ${{ vars.APP_NAME }} >> pr_message.txt
echo "" >> pr_message.txt
echo '```' >> pr_message.txt
echo "" >> pr_message.txt
echo "</details>" >> pr_message.txt
fi
cat pr_message.txt
- name: comment pr
Expand Down
41 changes: 10 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,48 +77,27 @@ As Developer, in Humanitec.
### All in once

```bash
FIRST_WORKLOAD="adservice"
COMBINED_DELTA=$(score-humanitec delta \
--app ${ONLINEBOUTIQUE_APP} \
--env ${ENVIRONMENT} \
--org ${HUMANITEC_ORG} \
--token ${HUMANITEC_TOKEN} \
--retry \
-f apps/${FIRST_WORKLOAD}/score.yaml \
--extensions apps/${FIRST_WORKLOAD}/humanitec.score.yaml \
| jq -r .id)
WORKLOADS="cartservice checkoutservice currencyservice emailservice frontend loadgenerator paymentservice productcatalogservice recommendationservice shippingservice"
for w in ${WORKLOADS}; \
do \
COMBINED_DELTA=$(score-humanitec delta \
--app ${ONLINEBOUTIQUE_APP} \
--env ${ENVIRONMENT} \
--org ${HUMANITEC_ORG} \
--token ${HUMANITEC_TOKEN} \
--delta ${COMBINED_DELTA} \
--retry \
-f apps/$w/score.yaml \
--extensions apps/$w/humanitec.score.yaml \
| jq -r .id); \
done
humctl deploy delta ${COMBINED_DELTA} ${ENVIRONMENT} \
--app ${ONLINEBOUTIQUE_APP}
humctl score deploy \
--app ${ONLINEBOUTIQUE_APP} \
--env ${ENVIRONMENT} \
--org ${HUMANITEC_ORG} \
--token ${HUMANITEC_TOKEN} \
-f apps/${WORKLOAD}/score.yaml \
--wait
```
_Note: `loadgenerator` is deployed to generate both: traffic on these apps and data in the database. If you don't want this, feel free to remove it from the above list of `WORKLOADS`._

### One by one

```bash
WORKLOAD=adservice #cartservice checkoutservice currencyservice emailservice frontend loadgenerator paymentservice productcatalogservice recommendationservice shippingservice
score-humanitec delta \
humctl score deploy \
--app ${ONLINEBOUTIQUE_APP} \
--env ${ENVIRONMENT} \
--org ${HUMANITEC_ORG} \
--token ${HUMANITEC_TOKEN} \
--deploy \
--retry \
-f apps/${WORKLOAD}/score.yaml \
--extensions apps/${WORKLOAD}/humanitec.score.yaml
--extensions apps/${WORKLOAD}/humanitec.score.yaml \
--wait
```

## Test the Online Boutique website
Expand Down
34 changes: 34 additions & 0 deletions apps/score.deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
workloads:
- name: onlineboutique/adservice
specFile: ./adservice/score.yaml
extensionsFile: ./adservice/humanitec.score.yaml
- name: onlineboutique/cartservice
specFile: ./cartservice/score.yaml
extensionsFile: ./cartservice/humanitec.score.yaml
- name: onlineboutique/checkoutservice
specFile: ./checkoutservice/score.yaml
extensionsFile: ./checkoutservice/humanitec.score.yaml
- name: onlineboutique/currencyservice
specFile: ./currencyservice/score.yaml
extensionsFile: ./currencyservice/humanitec.score.yaml
- name: onlineboutique/emailservice
specFile: ./emailservice/score.yaml
extensionsFile: ./emailservice/humanitec.score.yaml
- name: onlineboutique/frontend
specFile: ./frontend/score.yaml
extensionsFile: ./frontend/humanitec.score.yaml
- name: onlineboutique/loadgenerator
specFile: ./loadgenerator/score.yaml
extensionsFile: ./loadgenerator/humanitec.score.yaml
- name: onlineboutique/paymentservice
specFile: ./paymentservice/score.yaml
extensionsFile: ./paymentservice/humanitec.score.yaml
- name: onlineboutique/productcatalogservice
specFile: ./productcatalogservice/score.yaml
extensionsFile: ./productcatalogservice/humanitec.score.yaml
- name: onlineboutique/recommendationservice
specFile: ./recommendationservice/score.yaml
extensionsFile: ./recommendationservice/humanitec.score.yaml
- name: onlineboutique/shippingservice
specFile: ./shippingservice/score.yaml
extensionsFile: ./shippingservice/humanitec.score.yaml

0 comments on commit 05cc91d

Please sign in to comment.