Skip to content

Commit

Permalink
change deploy.yaml to auto commit to the fleet repo to execute deploy…
Browse files Browse the repository at this point in the history
…ments.
  • Loading branch information
hahn-kev committed Jul 21, 2023
1 parent a51c41d commit be9f912
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 50 deletions.
77 changes: 35 additions & 42 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
on:
workflow_call:
inputs:
expected-api-version:
description: 'The version of the API to deploy (TODO, currently only the version to verify, it deploys latest always right now)'
version:
description: 'The version of the image to deploy'
type: string
deployment:
description: 'The k8s deployment to update'
required: true
image:
description: 'The image to update'
type: string
default: 'lexbox'
required: true

jobs:
deploy:
Expand All @@ -18,43 +19,35 @@ jobs:
name: staging
url: https://staging.languagedepot.org
steps:
- name: Deploy
uses: drlove2002/[email protected]
- name: Checkout lexbox repo
uses: actions/checkout@v3
with:
url: ${{ vars.DEPLOY_WEBHOOK_URL }}
hmacSecret: ${{ secrets.DEPLOY_KEY }}
data: >-
{
"action" : "push",
"ref" : "${{ github.ref }}",
"version": "${{ inputs.expected-api-version }}",
"deployment": "${{ inputs.deployment }}"
}
- name: Verify Version
if: ${{ inputs.expected-api-version && inputs.deployment == 'lexbox' }}
env:
TARGET_HOST: https://staging.languagedepot.org
EXPECTED_VERSION: ${{ inputs.expected-api-version }}
path: lexbox
- name: Run kustomize
working-directory: lexbox/deployment/staging
run: |
IterateCount=5
DelayMultiplier=5
n=0
until [ $n -ge $IterateCount ]
do
curl -s --head "$TARGET_HOST/api/healthz" > response.txt
# get version from response, trim off the header and fix the line endings
versionHeader=$((grep "lexbox-version" response.txt || echo VersionNotFound) | cut -d' ' -f 2 | tr -d '[:space:]')
if [[ "$versionHeader" == "$EXPECTED_VERSION" ]]; then
echo "Version is correct"
exit 0
else
echo "Version '$versionHeader' is incorrect, expected '$EXPECTED_VERSION'"
echo "response was:"
cat response.txt
n=$((n+1))
sleep $((DelayMultiplier * n))
fi
done
kubectl kustomize -k . -o resources.yaml
- name: Checkout fleet repo
uses: actions/checkout@v3
with:
repository: ${{ vars.FLEET_REPO }}
# todo set some kind of access token, either pat or ssh
path: fleet
- name: Copy yaml resources to fleet repo
run: |
cp lexbox/deployment/staging/resources.yaml fleet/languageforge-lexbox/
# this kustomization file is in the fleet repo and only modifies the image versions being used.
- name: Update image version in fleet kustomization.yaml
uses: mikefarah/yq@v4
with:
cmd: yq -i '(.images.[] | select(.name == "${{ inputs.image }}").newTag) = "${{ inputs.version }}"' fleet/languageforge-lexbox/kustomization.yaml
- name: Push to fleet repo
uses: EndBug/add-and-commit@v9
with:
default_author: github_actions
message: "[Lexbox] Update image: ${{ inputs.image }} to ${{ inputs.version }}"
cwd: './fleet/'
add: 'languageforge-lexbox/*'
push: true


echo "Version $versionHeader is still incorrect after waiting"
exit 1
36 changes: 32 additions & 4 deletions .github/workflows/lexbox-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ on:

env:
PROD_RELEASE: ${{github.ref == vars.PROD_BRANCH}}
IMAGE_NAME: ghcr.io/sillsdev/lexbox-api


jobs:
Expand Down Expand Up @@ -80,7 +81,7 @@ jobs:
if: ${{ !env.ACT }}
uses: docker/metadata-action@v4
with:
images: ghcr.io/sillsdev/lexbox-api
images: ${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
Expand Down Expand Up @@ -108,8 +109,8 @@ jobs:
name: Deploy to k8s
uses: ./.github/workflows/deploy.yaml
with:
expected-api-version: ${{ needs.publish-api.outputs.version }}
deployment: lexbox #k8s deployment name
version: ${{ needs.publish-api.outputs.version }}
image: ${{ env.IMAGE_NAME }}
secrets: inherit
needs: publish-api
if: ${{ github.ref == vars.PROD_BRANCH }}
Expand All @@ -118,8 +119,35 @@ jobs:
permissions:
checks: write
runs-on: ubuntu-latest
needs: deploy-api
needs: [deploy-api, publish-api]
steps:
- name: Verify Version
env:
TARGET_HOST: https://staging.languagedepot.org
EXPECTED_VERSION: ${{ needs.publish-api.outputs.version }}
run: |
IterateCount=5
DelayMultiplier=5
n=0
until [ $n -ge $IterateCount ]
do
curl -s --head "$TARGET_HOST/api/healthz" > response.txt
# get version from response, trim off the header and fix the line endings
versionHeader=$((grep "lexbox-version" response.txt || echo VersionNotFound) | cut -d' ' -f 2 | tr -d '[:space:]')
if [[ "$versionHeader" == "$EXPECTED_VERSION" ]]; then
echo "Version is correct"
exit 0
else
echo "Version '$versionHeader' is incorrect, expected '$EXPECTED_VERSION'"
echo "response was:"
cat response.txt
n=$((n+1))
sleep $((DelayMultiplier * n))
fi
done
echo "Version $versionHeader is still incorrect after waiting"
exit 1
- uses: actions/checkout@v3
- uses: ./.github/actions/dotnet-integration
name: Integration Tests
Expand Down
13 changes: 12 additions & 1 deletion .github/workflows/lexbox-hgweb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ on:

env:
PROD_RELEASE: ${{github.ref == vars.PROD_BRANCH}}
IMAGE_NAME: ghcr.io/sillsdev/lexbox-hgweb

jobs:
publish-hgweb:
runs-on: ubuntu-latest
Expand All @@ -35,13 +37,14 @@ jobs:
# set version to date in vYYYY-MM-DD format
run: |
echo "VERSION=v$(date --rfc-3339=date)" >> ${GITHUB_ENV}
echo "VERSION=v$(date --rfc-3339=date)" >> ${GITHUB_OUTPUT}
- name: Docker meta
id: meta
if: ${{ !env.ACT }}
uses: docker/metadata-action@v4
with:
images: ghcr.io/sillsdev/lexbox-hgweb
images: ${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
Expand All @@ -62,3 +65,11 @@ jobs:
push: ${{ !env.ACT }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
deploy-hgweb:
uses: ./.github/workflows/deploy.yaml
if: ${{github.ref == vars.PROD_BRANCH}}
secrets: inherit
needs: publish-hgweb
with:
version: ${{ needs.publish-hgweb.outputs.version }}
image: ${{ env.IMAGE_NAME }}
7 changes: 4 additions & 3 deletions .github/workflows/lexbox-ui.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ on:

env:
PROD_RELEASE: ${{github.ref == vars.PROD_BRANCH}}
IMAGE_NAME: ghcr.io/sillsdev/lexbox-ui

jobs:
publish-ui:
Expand Down Expand Up @@ -61,7 +62,7 @@ jobs:
if: ${{ !env.ACT }}
uses: docker/metadata-action@v4
with:
images: ghcr.io/sillsdev/lexbox-ui
images: ${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
Expand All @@ -88,8 +89,8 @@ jobs:
secrets: inherit
needs: publish-ui
with:
deployment: ui #k8s deployment name
expected-api-version: ${{ needs.publish-ui.outputs.version }}
version: ${{ needs.publish-ui.outputs.version }}
image: ${{ env.IMAGE_NAME }}

check-and-lint:
runs-on: ubuntu-latest
Expand Down

0 comments on commit be9f912

Please sign in to comment.