diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a35bf2a..20c5cb8 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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 }} diff --git a/.github/workflows/frontend-close-pr.yaml b/.github/workflows/frontend-close-pr.yaml index 82265f6..bfe9e37 100644 --- a/.github/workflows/frontend-close-pr.yaml +++ b/.github/workflows/frontend-close-pr.yaml @@ -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 diff --git a/.github/workflows/frontend-pr.yaml b/.github/workflows/frontend-pr.yaml index f22d559..7bfd49d 100644 --- a/.github/workflows/frontend-pr.yaml +++ b/.github/workflows/frontend-pr.yaml @@ -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 @@ -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 }} \ @@ -148,16 +118,39 @@ jobs: echo "" >> pr_message.txt echo "" >> pr_message.txt - echo "
Score Output" >> 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 "
" >> pr_message.txt + if [ "$DEPLOYMENT_ERRORS" = "[]" ]; then + echo "
Active Resources Usage" >> 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 "
" >> pr_message.txt + fi + + if [ "$DEPLOYMENT_ERRORS" = "[]" ]; then + echo "
Resources Graph" >> 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 "
" >> pr_message.txt + fi cat pr_message.txt - name: comment pr diff --git a/README.md b/README.md index a69a7c2..6a58b76 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/apps/score.deploy.yaml b/apps/score.deploy.yaml new file mode 100644 index 0000000..0e0be13 --- /dev/null +++ b/apps/score.deploy.yaml @@ -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 \ No newline at end of file