Skip to content

Commit

Permalink
ci: ensure image is built and published once
Browse files Browse the repository at this point in the history
  • Loading branch information
arealmaas committed Nov 27, 2024
1 parent 12e4b0b commit c8f4011
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 48 deletions.
46 changes: 27 additions & 19 deletions .github/workflows/ci-cd-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
release-please:
name: Release please
runs-on: ubuntu-latest
outputs:
release_created: ${{ steps.release.outputs.release_created }}
steps:
- uses: googleapis/release-please-action@v4
id: release
Expand All @@ -43,17 +45,22 @@ jobs:
needs: [check-for-changes]
if: ${{ github.event_name == 'workflow_dispatch' || needs.check-for-changes.outputs.hasBackendChanges == 'true' || needs.check-for-changes.outputs.hasTestChanges == 'true' }}

publish:
name: Build and publish docker images
publish-release:
name: Build and publish release docker images
uses: ./.github/workflows/workflow-publish.yml
needs:
[
get-current-version,
check-for-changes,
generate-git-short-sha,
build-and-test,
]
if: ${{ github.event_name == 'workflow_dispatch' || needs.check-for-changes.outputs.hasBackendChanges == 'true' }}
needs: [release-please, get-current-version, build-and-test]
if: ${{ needs.release-please.outputs.release_created == 'true' }}
secrets:
GCR_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
with:
dockerImageBaseName: ghcr.io/digdir/dialogporten-
version: ${{ needs.get-current-version.outputs.version }}

publish-main:
name: Build and publish main docker images
uses: ./.github/workflows/workflow-publish.yml
needs: [get-current-version, check-for-changes, generate-git-short-sha, build-and-test]
if: ${{ needs.release-please.outputs.release_created != 'true' && (github.event_name == 'workflow_dispatch' || needs.check-for-changes.outputs.hasBackendChanges == 'true') }}
secrets:
GCR_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
with:
Expand All @@ -63,7 +70,7 @@ jobs:
deploy-infra:
name: Deploy infra to test
needs: [get-current-version, check-for-changes, generate-git-short-sha]
if: ${{ github.event_name == 'workflow_dispatch' || needs.check-for-changes.outputs.hasInfraChanges == 'true' }}
if: ${{ needs.release-please.outputs.release_created != 'true' && (github.event_name == 'workflow_dispatch' || needs.check-for-changes.outputs.hasInfraChanges == 'true') }}
uses: ./.github/workflows/workflow-deploy-infra.yml
secrets:
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
Expand All @@ -85,17 +92,16 @@ jobs:
get-current-version,
check-for-changes,
generate-git-short-sha,
publish,
publish-main,
deploy-infra,
]
# we want deployment of apps to be dependent on deployment of infrastructure, but if infrastructure is skipped, we still want to deploy the apps
if: ${{ always() && !failure() && !cancelled() && (github.event_name == 'workflow_dispatch' || needs.check-for-changes.outputs.hasBackendChanges == 'true') }}
if: ${{ always() && !failure() && !cancelled() && needs.release-please.outputs.release_created != 'true' && (github.event_name == 'workflow_dispatch' || needs.check-for-changes.outputs.hasBackendChanges == 'true') }}
uses: ./.github/workflows/workflow-deploy-apps.yml
secrets:
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
# todo: consider resolving these in another way since they are created in the infra-step
AZURE_RESOURCE_GROUP_NAME: ${{ secrets.AZURE_RESOURCE_GROUP_NAME }}
AZURE_ENVIRONMENT_KEY_VAULT_NAME: ${{ secrets.AZURE_ENVIRONMENT_KEY_VAULT_NAME }}
AZURE_CONTAINER_APP_ENVIRONMENT_NAME: ${{ secrets.AZURE_CONTAINER_APP_ENVIRONMENT_NAME }}
Expand All @@ -111,7 +117,7 @@ jobs:
deploy-slack-notifier:
name: Deploy slack notifier (test)
needs: [check-for-changes]
if: ${{ github.event_name == 'workflow_dispatch' || needs.check-for-changes.outputs.hasSlackNotifierChanges == 'true' }}
if: ${{ needs.release-please.outputs.release_created != 'true' && (github.event_name == 'workflow_dispatch' || needs.check-for-changes.outputs.hasSlackNotifierChanges == 'true') }}
uses: ./.github/workflows/workflow-deploy-function.yml
secrets:
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
Expand All @@ -127,7 +133,7 @@ jobs:
publish-schema-npm:
name: Deploy schema npm package
needs: [check-for-changes, get-current-version, generate-git-short-sha, deploy-apps]
if: ${{ always() && !failure() && !cancelled() && (github.event_name == 'workflow_dispatch' || needs.check-for-changes.outputs.hasSchemaChanges == 'true') }}
if: ${{ always() && !failure() && !cancelled() && needs.release-please.outputs.release_created != 'true' && (github.event_name == 'workflow_dispatch' || needs.check-for-changes.outputs.hasSchemaChanges == 'true') }}
uses: ./.github/workflows/workflow-publish-schema.yml
with:
version: ${{ needs.get-current-version.outputs.version }}-${{ needs.generate-git-short-sha.outputs.gitShortSha }}
Expand All @@ -137,7 +143,7 @@ jobs:
run-e2e-tests:
name: "Run K6 functional end-to-end tests"
# we want the end-to-end tests to be dependent on deployment of infrastructure and apps, but if infrastructure is skipped, we still want to run the tests
if: ${{ always() && !failure() && !cancelled() && (github.event_name == 'workflow_dispatch' || needs.check-for-changes.outputs.hasBackendChanges == 'true' || needs.check-for-changes.outputs.hasTestChanges == 'true') }}
if: ${{ always() && !failure() && !cancelled() && needs.release-please.outputs.release_created != 'true' && (github.event_name == 'workflow_dispatch' || needs.check-for-changes.outputs.hasBackendChanges == 'true' || needs.check-for-changes.outputs.hasTestChanges == 'true') }}
needs: [deploy-apps, check-for-changes]
uses: ./.github/workflows/workflow-run-k6-tests.yml
secrets:
Expand All @@ -159,7 +165,8 @@ jobs:
deploy-slack-notifier,
run-e2e-tests,
publish-schema-npm,
publish,
publish-release,
publish-main,
build-and-test,
]
if: ${{ always() && failure() && !cancelled() }}
Expand All @@ -171,7 +178,8 @@ jobs:
slack_notifier_status: ${{ needs.deploy-slack-notifier.result }}
e2e_tests_status: ${{ needs.run-e2e-tests.result }}
schema_npm_status: ${{ needs.publish-schema-npm.result }}
publish_status: ${{ needs.publish.result }}
# todo: fix so that we have multiple statuses
publish_status: ${{ needs.publish-release.result }}
build_and_test_status: ${{ needs.build-and-test.result }}
secrets:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
Expand Down
16 changes: 2 additions & 14 deletions .github/workflows/ci-cd-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,10 @@ jobs:
secrets:
GH_TOKEN: ${{ secrets.RELEASE_VERSION_STORAGE_PAT }}

publish:
name: Build and publish docker images
uses: ./.github/workflows/workflow-publish.yml
if: ${{ github.event_name == 'workflow_dispatch' || needs.check-for-changes.outputs.hasBackendChanges == 'true' }}
needs: [get-current-version, check-for-changes]
secrets:
GCR_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
with:
dockerImageBaseName: ghcr.io/digdir/dialogporten-
version: ${{ needs.get-current-version.outputs.version }}

deploy-apps:
name: Deploy apps to staging
needs:
[get-current-version, check-for-changes, deploy-infra, publish]
[get-current-version, check-for-changes, deploy-infra]
if: ${{ always() && !failure() && !cancelled() && (github.event_name == 'workflow_dispatch' || needs.check-for-changes.outputs.hasBackendChanges == 'true') }}
uses: ./.github/workflows/workflow-deploy-apps.yml
secrets:
Expand Down Expand Up @@ -150,7 +139,7 @@ jobs:

send-slack-message-on-failure:
name: Send Slack message on failure
needs: [deploy-infra, deploy-apps, deploy-slack-notifier, run-e2e-tests, publish-schema-npm, publish]
needs: [deploy-infra, deploy-apps, deploy-slack-notifier, run-e2e-tests, publish-schema-npm]
if: ${{ always() && failure() && !cancelled() }}
uses: ./.github/workflows/workflow-send-ci-cd-status-slack-message.yml
with:
Expand All @@ -160,7 +149,6 @@ jobs:
slack_notifier_status: ${{ needs.deploy-slack-notifier.result }}
e2e_tests_status: ${{ needs.run-e2e-tests.result }}
schema_npm_status: ${{ needs.publish-schema-npm.result }}
publish_status: ${{ needs.publish.result }}
secrets:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
SLACK_CHANNEL_ID: ${{ secrets.SLACK_CHANNEL_ID_FOR_CI_CD_STATUS }}
17 changes: 2 additions & 15 deletions .github/workflows/ci-cd-yt01.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,6 @@ jobs:
name: Get current version
uses: ./.github/workflows/workflow-get-current-version.yml

publish:
name: Build and publish docker images
uses: ./.github/workflows/workflow-publish.yml
if: ${{ github.event_name == 'workflow_dispatch' || needs.check-for-changes.outputs.hasBackendChanges == 'true' }}
needs: [get-current-version, check-for-changes]
secrets:
GCR_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
with:
dockerImageBaseName: ghcr.io/digdir/dialogporten-
version: ${{ needs.get-current-version.outputs.version }}

deploy-infra:
name: Deploy infra to yt01
if: ${{ github.event_name == 'workflow_dispatch' || needs.check-for-changes.outputs.hasInfraChanges == 'true' }}
Expand Down Expand Up @@ -74,8 +63,7 @@ jobs:
deploy-apps:
name: Deploy apps to yt01
needs:
[get-current-version, check-for-changes, deploy-infra, publish]
# we want deployment of apps to be dependent on deployment of infrastructure, but if infrastructure is skipped, we still want to deploy the apps
[get-current-version, check-for-changes, deploy-infra]
if: ${{ always() && !failure() && !cancelled() && (github.event_name == 'workflow_dispatch' || needs.check-for-changes.outputs.hasBackendChanges == 'true') }}
uses: ./.github/workflows/workflow-deploy-apps.yml
secrets:
Expand Down Expand Up @@ -142,7 +130,7 @@ jobs:

send-slack-message-on-failure:
name: Send Slack message on failure
needs: [deploy-infra, deploy-apps, deploy-slack-notifier, run-e2e-tests, publish]
needs: [deploy-infra, deploy-apps, deploy-slack-notifier, run-e2e-tests]
if: ${{ always() && failure() && !cancelled() }}
uses: ./.github/workflows/workflow-send-ci-cd-status-slack-message.yml
with:
Expand All @@ -151,7 +139,6 @@ jobs:
apps_status: ${{ needs.deploy-apps.result }}
slack_notifier_status: ${{ needs.deploy-slack-notifier.result }}
e2e_tests_status: ${{ needs.run-e2e-tests.result }}
publish_status: ${{ needs.publish.result }}
secrets:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
SLACK_CHANNEL_ID: ${{ secrets.SLACK_CHANNEL_ID_FOR_CI_CD_STATUS }}

0 comments on commit c8f4011

Please sign in to comment.