|
name: Test-and-Deployment |
|
|
|
concurrency: |
|
group: ci-${{ github.ref }} |
|
cancel-in-progress: false |
|
|
|
env: |
|
SETOPS_WEB_APP: "web" |
|
SETOPS_WORKER_APP: "worker" |
|
SETOPS_CLOCK_APP: "clock" |
|
SETOPS_IMAGE: "IMAGENAME" |
|
SETOPS_STAGE_PREFIX: "ccmycv" |
|
SETOPS_HOST: "zweitag.setops.net" |
|
|
|
jobs: |
|
deploy: |
|
name: deploy |
|
runs-on: ubuntu-latest |
|
needs: [test, yarn_eslint, rufo-and-rubocop] # put your other jobs here |
|
if: github.ref == 'refs/heads/production' || github.ref == 'refs/heads/staging' |
|
steps: |
|
# ----- Set env.SETOPS_STAGE from current branch ------ |
|
- name: "[Config] Extract branch name" |
|
run: | |
|
echo "BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV |
|
|
|
# Set App env by branch name |
|
- name: "[Config] Set up app env 'staging'" |
|
if: env.BRANCH_NAME == 'staging' |
|
run: | |
|
echo "APP_ENV=staging" >> $GITHUB_ENV |
|
- name: "[Config] Set up app env 'production'" |
|
if: env.BRANCH_NAME == 'production' |
|
run: | |
|
echo "APP_ENV=production" >> $GITHUB_ENV |
|
|
|
# Stop here if no app env could be determined |
|
- name: "[Config] Validate app env" |
|
if: env.APP_ENV == '' |
|
run: | |
|
echo "⚠️ Could not determine app env for branch ${{ env.BRANCH_NAME }}" |
|
exit 1 |
|
|
|
- name: "[Config] Prepare Setops config" |
|
run: | |
|
echo "SETOPS_STAGE=${{ env.SETOPS_STAGE_PREFIX}}-${{ env.APP_ENV }}" >> $GITHUB_ENV |
|
echo "SETOPS_TARGET_IMAGE=${{ env.SETOPS_HOST }}/${{ env.SETOPS_STAGE_PREFIX }}/${{ env.APP_ENV }}:${{ env.SETOPS_WEB_APP }}" >> $GITHUB_ENV |
|
|
|
- name: "[Config] Summarize Config" |
|
run: | |
|
echo "Branch name: ${{ env.BRANCH_NAME }}" |
|
echo "App env: ${{ env.APP_ENV }}" |
|
echo "Setops Stage: ${{ env.SETOPS_STAGE }}" |
|
echo "Image: ${{ env.SETOPS_IMAGE }}" |
|
echo "Target Image: ${{ env.SETOPS_TARGET_IMAGE }}" |
|
|
|
# ----- Install dependencies ----- |
|
- name: "[Setup] Install Setops" |
|
uses: setopsco/setup-setops@v1 |
|
with: |
|
setops_url: https://${{ env.SETOPS_HOST }} |
|
setops_username: ${{ secrets.SETOPS_USER }} |
|
setops_password: ${{ secrets.SETOPS_PASSWORD }} |
|
|
|
- name: "[Setup] Get Setops login command" |
|
run: | |
|
LOGIN_COMMAND=$(setops registry get-login-command | grep printf) |
|
eval $LOGIN_COMMAND |
|
|
|
# ----- Discard old Changeset ----- |
|
- name: "[Setup] Discard old Changeset" |
|
run: | |
|
setops --stage ${{ env.SETOPS_STAGE }} discard || true |
|
|
|
- name: "[Setup] Install Pack CLI" |
|
uses: buildpacks/github-actions/setup-pack@main |
|
|
|
# ----- Build image ----- |
|
- name: "[Build] Checkout repository" |
|
uses: actions/checkout@v2 |
|
|
|
- name: "[Build] Set git revision" |
|
run: | |
|
git rev-parse --short "$GITHUB_SHA" > .git_revision |
|
|
|
- name: "[Build] Build image" |
|
run: | |
|
pack build ${{ env.SETOPS_IMAGE }} --builder heroku/buildpacks:20 --env-file=".env.build" |
|
|
|
# ----- Push image ----- |
|
- name: "[Push] Tag image" |
|
run: | |
|
docker tag ${{ env.SETOPS_IMAGE}}:latest ${{ env.SETOPS_TARGET_IMAGE }} |
|
|
|
- name: "[Push] Push image" |
|
run: | |
|
SETOPS_DIGEST=$(docker push ${{ env.SETOPS_TARGET_IMAGE }} | grep -o 'sha256:[a-zA-Z0-9]*') |
|
echo "SETOPS_DIGEST=$SETOPS_DIGEST" >> $GITHUB_ENV |
|
|
|
# ----- Create releases ----- |
|
- name: "[Release] Create web release" |
|
run: | |
|
SETOPS_RELEASE_ID_WEB=$(setops --stage ${{ env.SETOPS_STAGE }} app release create ${{ env.SETOPS_WEB_APP }} --digest ${{ env.SETOPS_DIGEST }} | grep -o 'ReleaseID.*' | grep -o '[0-9].*') |
|
echo "SETOPS_RELEASE_ID_WEB=$SETOPS_RELEASE_ID_WEB" >> $GITHUB_ENV |
|
|
|
- name: "[Release] Create worker release" |
|
run: | |
|
SETOPS_RELEASE_ID_WORKER=$(setops --stage ${{ env.SETOPS_STAGE }} app release create ${{ env.SETOPS_WORKER_APP }} --digest ${{ env.SETOPS_DIGEST }} | grep -o 'ReleaseID.*' | grep -o '[0-9].*') |
|
echo "SETOPS_RELEASE_ID_WORKER=$SETOPS_RELEASE_ID_WORKER" >> $GITHUB_ENV |
|
|
|
- name: "[Release] Create clock release" |
|
run: | |
|
SETOPS_RELEASE_ID_CLOCK=$(setops --stage ${{ env.SETOPS_STAGE }} app release create ${{ env.SETOPS_CLOCK_APP }} --digest ${{ env.SETOPS_DIGEST }} | grep -o 'ReleaseID.*' | grep -o '[0-9].*') |
|
echo "SETOPS_RELEASE_ID_CLOCK=$SETOPS_RELEASE_ID_CLOCK" >> $GITHUB_ENV |
|
- name: "[Release] Setops commit" |
|
run: | |
|
setops --stage ${{ env.SETOPS_STAGE }} status |
|
setops --stage ${{ env.SETOPS_STAGE }} --output plain commit |
|
|
|
# ----- Run deploy tasks ----- |
|
- name: "[Release] Run Deploy Tasks" |
|
run: | |
|
setops --stage ${{ env.SETOPS_STAGE }} run ${{ env.SETOPS_WEB_APP }} --debug --release ${{ env.SETOPS_RELEASE_ID_WEB}} -- './bin/run_deploy_tasks' |
|
|
|
# ----- Activate release ----- |
|
- name: "[Release] Activate WEB release" |
|
run: | |
|
setops --stage ${{ env.SETOPS_STAGE }} app release set ${{ env.SETOPS_WEB_APP }} ${{ env.SETOPS_RELEASE_ID_WEB }} |
|
|
|
- name: "[Release] Activate WORKER release" |
|
run: | |
|
setops --stage ${{ env.SETOPS_STAGE }} app release set ${{ env.SETOPS_WORKER_APP }} ${{ env.SETOPS_RELEASE_ID_WORKER }} |
|
|
|
- name: "[Release] Activate CLOCK release" |
|
run: | |
|
setops --stage ${{ env.SETOPS_STAGE }} app release set ${{ env.SETOPS_CLOCK_APP }} ${{ env.SETOPS_RELEASE_ID_CLOCK }} |
|
|
|
- name: "[Release] Setops commit" |
|
run: | |
|
setops --stage ${{ env.SETOPS_STAGE }} status |
|
setops --stage ${{ env.SETOPS_STAGE }} --output plain commit |
|
|
|
- name: "[Release] Wait for Healthy WEB Container" |
|
timeout-minutes: 2 |
|
run: | |
|
until setops --stage ${{ env.SETOPS_STAGE }} app ps ${{ env.SETOPS_WEB_APP }} |grep -w -E "${{ env.SETOPS_RELEASE_ID_WEB }}.*HEALTHY" |
|
do |
|
echo "Container not up & healthy, retry in 5 seconds" |
|
sleep 5 |
|
done |
|
|
|
- name: "[Release] Wait for Healthy WORKER Container" |
|
timeout-minutes: 2 |
|
run: | |
|
until setops --stage ${{ env.SETOPS_STAGE }} app ps ${{ env.SETOPS_WORKER_APP }} |grep -w -E "${{ env.SETOPS_RELEASE_ID_WORKER }}.*RUNNING" |
|
do |
|
echo "Container not up & healthy, retry in 5 seconds" |
|
sleep 5 |
|
done |
|
|
|
- name: "[Release] Wait for Healthy CLOCK Container" |
|
timeout-minutes: 2 |
|
run: | |
|
until setops --stage ${{ env.SETOPS_STAGE }} app ps ${{ env.SETOPS_CLOCK_APP }} |grep -w -E "${{ env.SETOPS_RELEASE_ID_CLOCK }}.*RUNNING" |
|
do |
|
echo "Container not up & healthy, retry in 5 seconds" |
|
sleep 5 |
|
done |
|
|
|
- name: "Summarize Deployment" |
|
run: | |
|
echo "✅ Action succeeded!" |
|
echo "-------------------------" |
|
echo "Setops Web App: ${{ env.SETOPS_WEB_APP }}" |
|
echo "Setops Worker App: ${{ env.SETOPS_WORKER_APP }}" |
|
echo "Setops Clock App: ${{ env.SETOPS_CLOCK_APP }}" |
|
echo "Setops Stage: ${{ env.SETOPS_STAGE }}" |
|
echo "Image Digest: ${{ env.SETOPS_DIGEST }}" |
|
echo "Release ID Web: ${{ env.SETOPS_RELEASE_ID_WEB }}" |
|
echo "Release ID Worker: ${{ env.SETOPS_RELEASE_ID_WORKER }}" |
|
echo "Release ID Clock: ${{ env.SETOPS_RELEASE_ID_CLOCK }}" |
Hmm didn't think about that. Actually, then we still have the concurrency problem like before.
The situation would be that you committed 2 times to production and the later commit is slower in CI, leading to concurrency. Any idea about that? We already discussed that here.