-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2984 from statisticsnorway/develop
Deploy to Production
- Loading branch information
Showing
12 changed files
with
2,452 additions
and
1,840 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,27 @@ | ||
name: NAIS Deploy | ||
name: NAIS Delete | ||
|
||
on: workflow_dispatch | ||
|
||
on: | ||
pull_request: | ||
types: [closed] | ||
|
||
jobs: | ||
delete: | ||
name: 'Delete app from cluster' | ||
permissions: | ||
contents: "read" | ||
id-token: "write" | ||
contents: 'read' | ||
id-token: 'write' | ||
runs-on: ubuntu-latest | ||
if: (startsWith(github.head_ref, 'MIM-') || startsWith(github.head_ref, 'mim-') && contains(github.event.issue.labels.*.name, 'nais') && contains(fromJSON('["annesiri", "ssb-cgn", "Glenruben", "johnnadeluy", "Carl-OW", "michaelpande"]'), github.actor)) | ||
if: (startsWith(github.head_ref, 'MIM-') || startsWith(github.head_ref, 'mim-') && contains(github.event.pull_request.labels.*.name, 'nais') && contains(fromJSON('["annesiri", "ssb-cgn", "Glenruben", "johnnadeluy", "Carl-OW", "michaelpande"]'), github.actor)) | ||
env: | ||
REGISTRY: europe-north1-docker.pkg.dev/nais-management-b3a7/ssbno/ssbno-mimir | ||
IMAGE: mimir | ||
steps: | ||
# turn 'MIM-9876_new_feature' into 'mim-9876' so it can be used in URL, it can be found in env.ISSUE_NUMBER | ||
- name: "Get JIRA issue number" | ||
# Checkout the PR branch (e.g., MIM-2005-nais-deploy-test-6) | ||
- name: Checkout the PR branch | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.head_ref }} # Check out the branch associated with the PR | ||
|
||
# Get the JIRA issue number (same logic from deploy) | ||
- name: 'Get JIRA issue number' | ||
id: jira_issue_number | ||
run: | | ||
BRANCH="${{ github.head_ref }}" | ||
|
@@ -23,17 +30,40 @@ jobs: | |
echo "ISSUE_NUMBER=${ISSUE_NUMBER}" >> $GITHUB_ENV; | ||
echo "Issue number: $ISSUE_NUMBER"; | ||
- id: "auth" | ||
name: "Authenticate to Google Cloud" | ||
uses: "google-github-actions/[email protected]" | ||
# Authenticate to Google Cloud | ||
- id: 'auth' | ||
name: 'Authenticate to Google Cloud' | ||
uses: 'google-github-actions/[email protected]' | ||
with: | ||
workload_identity_provider: "projects/906675412832/locations/global/workloadIdentityPools/ssb-identity-pool/providers/github-oidc-provider" | ||
service_account: "[email protected]" | ||
token_format: "access_token" | ||
- id: "get-credentials" | ||
uses: 'google-github-actions/get-gke-credentials@v2' | ||
with: | ||
cluster_name: 'nais-test' | ||
location: 'europe-north1' | ||
- id: "delete" | ||
run: "kubectl delete pod -n ssbno --selector=app=mimir-branch-${{ env.ISSUE_NUMBER }} --ignore-not-found=true" | ||
workload_identity_provider: 'projects/906675412832/locations/global/workloadIdentityPools/ssb-identity-pool/providers/github-oidc-provider' | ||
service_account: '[email protected]' | ||
token_format: 'access_token' | ||
|
||
# Verify nais.yaml exists | ||
- name: Verify nais.yaml exists | ||
run: | | ||
if [ ! -f "nais.yaml" ]; then | ||
echo "nais.yaml not found!" | ||
exit 1 | ||
else | ||
echo "nais.yaml found." | ||
fi | ||
# Modify nais.yaml to set TTL to "10m" (must be string value) | ||
- name: Set TTL to "10m" in nais.yaml | ||
run: | | ||
sed -i 's/ttl: .*/ttl: "10m"/' nais.yaml | ||
# Use the stored image tag from the deploy job | ||
- name: Retrieve the original image tag | ||
run: | | ||
echo "Using stored image tag: ${{ env.IMAGE_TAG }}" | ||
# Redeploy the application with the modified TTL and correct image and branch variables | ||
- uses: nais/deploy/actions/deploy@v2 | ||
env: | ||
APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }} | ||
CLUSTER: test | ||
RESOURCE: nais.yaml | ||
VAR: image=${{ env.REGISTRY }}/${{ env.IMAGE }}:${{ env.TAG }},branch=${{ env.ISSUE_NUMBER }} | ||
DEPLOY_SERVER: deploy.ssb.cloud.nais.io:443 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,13 +3,7 @@ name: NAIS Deploy | |
on: | ||
pull_request: | ||
types: [labeled] | ||
# types: [opened] | ||
# paths: | ||
# - 'src/**' | ||
# - 'build.gradle' | ||
# - 'package.json' | ||
|
||
|
||
env: | ||
REGISTRY: europe-north1-docker.pkg.dev/nais-management-b3a7/ssbno/ssbno-mimir | ||
IMAGE: mimir | ||
|
@@ -19,7 +13,7 @@ jobs: | |
build_xp: | ||
name: 'Build XP jar' | ||
runs-on: 'ubuntu-latest' | ||
if: (startsWith(github.head_ref, 'MIM-') || startsWith(github.head_ref, 'mim-') && github.event.label.name == 'nais' && contains(fromJSON('["annesiri", "ssb-cgn", "Glenruben", "johnnadeluy", "Carl-OW", "michaelpande"]'), github.actor)) | ||
if: (github.event.label.name == 'nais' && contains(fromJSON('["annesiri", "ssb-cgn", "Glenruben", "johnnadeluy", "Carl-OW", "michaelpande"]'), github.actor)) | ||
steps: | ||
- id: build_app | ||
uses: enonic/release-tools/build-and-publish@master | ||
|
@@ -31,14 +25,13 @@ jobs: | |
uses: actions/upload-artifact@v4 | ||
with: | ||
name: mimir-nais-${{ github.run_number }} | ||
path: "./build/libs/*.jar" | ||
|
||
path: './build/libs/*.jar' | ||
|
||
build_image_and_push: | ||
needs: build_xp | ||
permissions: | ||
contents: "read" | ||
id-token: "write" | ||
contents: 'read' | ||
id-token: 'write' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Calculate sha | ||
|
@@ -48,24 +41,29 @@ jobs: | |
- name: Checkout mimir | ||
uses: actions/checkout@v4 | ||
|
||
- name: Edit TTL for Undeploy | ||
if: github.event.pull_request.merged == true | ||
run: | | ||
sed -i 's/ttl: .*/ttl: "10m"/' nais.yaml | ||
- name: Give GitHub Actions acces to docker repo | ||
uses: webfactory/[email protected] | ||
with: | ||
ssh-private-key: ${{ secrets.DOCKER_REPO_READ_KEY }} | ||
- name: Checkout docker | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: "master" | ||
path: "ssbno-xp-docker" | ||
repository: "statisticsnorway/ssbno-xp-docker" | ||
ref: 'master' | ||
path: 'ssbno-xp-docker' | ||
repository: 'statisticsnorway/ssbno-xp-docker' | ||
- name: Download artifacts | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: mimir-nais-${{ github.run_number }} | ||
path: "./ssbno-xp-docker" | ||
path: './ssbno-xp-docker' | ||
|
||
# turn 'MIM-9876_new_feature' into 'mim-9876' so it can be used in URL, it can be found in env.ISSUE_NUMBER | ||
- name: "Get JIRA issue number" | ||
- name: 'Get JIRA issue number' | ||
id: jira_issue_number | ||
run: | | ||
BRANCH="${{ github.head_ref }}" | ||
|
@@ -74,22 +72,22 @@ jobs: | |
echo "ISSUE_NUMBER=${ISSUE_NUMBER}" >> $GITHUB_ENV; | ||
echo "Issue number: $ISSUE_NUMBER"; | ||
- id: "auth" | ||
name: "Authenticate to Google Cloud" | ||
uses: "google-github-actions/[email protected].5" | ||
- id: 'auth' | ||
name: 'Authenticate to Google Cloud' | ||
uses: 'google-github-actions/[email protected].6' | ||
with: | ||
workload_identity_provider: "projects/906675412832/locations/global/workloadIdentityPools/ssb-identity-pool/providers/github-oidc-provider" | ||
service_account: "[email protected]" | ||
token_format: "access_token" | ||
workload_identity_provider: 'projects/906675412832/locations/global/workloadIdentityPools/ssb-identity-pool/providers/github-oidc-provider' | ||
service_account: '[email protected]' | ||
token_format: 'access_token' | ||
- name: Set up Docker Buildx | ||
id: buildx | ||
uses: docker/setup-buildx-action@v3 | ||
- name: Login to registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: "oauth2accesstoken" | ||
password: "${{ steps.auth.outputs.access_token }}" | ||
username: 'oauth2accesstoken' | ||
password: '${{ steps.auth.outputs.access_token }}' | ||
- name: Docker meta | ||
id: metadata | ||
uses: docker/metadata-action@v5 | ||
|
@@ -109,31 +107,32 @@ jobs: | |
uses: docker/build-push-action@v6 | ||
with: | ||
context: ./ssbno-xp-docker | ||
file: "./ssbno-xp-docker/Dockerfile" | ||
file: './ssbno-xp-docker/Dockerfile' | ||
push: true | ||
tags: ${{ steps.metadata.outputs.tags }} | ||
# tags: ${{ github.ref_name }}-${{ github.sha }} | ||
labels: ${{ steps.metadata.outputs.labels }} | ||
|
||
|
||
deploy: | ||
name: Deploy to NAIS | ||
needs: build_image_and_push | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: "Get JIRA issue number" | ||
- name: 'Get JIRA issue number' | ||
id: jira_issue_number | ||
run: | | ||
BRANCH="${{ github.head_ref }}" | ||
ISSUE_NUMBER=${BRANCH:0:8} | ||
ISSUE_NUMBER=$(echo $ISSUE_NUMBER | tr '[:upper:]' '[:lower:]') | ||
echo "ISSUE_NUMBER=${ISSUE_NUMBER}" >> $GITHUB_ENV; | ||
echo "Issue number: $ISSUE_NUMBER"; | ||
- name: 'Store image tag' | ||
run: echo "IMAGE_TAG=${{ env.TAG }}" >> $GITHUB_ENV | ||
- uses: nais/deploy/actions/deploy@v2 | ||
env: | ||
APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }} | ||
CLUSTER: test | ||
RESOURCE: nais.yaml | ||
VAR: image=${{ env.REGISTRY }}/${{env.IMAGE}}:${{ env.TAG }},branch=${{ env.ISSUE_NUMBER }} | ||
DEPLOY_SERVER: deploy.ssb.cloud.nais.io:443 | ||
DEPLOY_SERVER: deploy.ssb.cloud.nais.io:443 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
apiVersion: backstage.io/v1alpha1 | ||
kind: Component | ||
metadata: | ||
name: mimir | ||
description: | | ||
Content Management Solution for ssb.no | ||
links: | ||
- title: Enonic Admin | ||
url: https://ssb-xp7p-admin.enonic.cloud/xp/admin/tool | ||
tags: | ||
- typescript | ||
- javascript | ||
- react | ||
- enonic-xp | ||
annotations: | ||
github.com/project-slug: statisticsnorway/mimir | ||
spec: | ||
type: website | ||
system: SSBNO | ||
owner: ssbno-developers | ||
lifecycle: production |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.