Skip to content

Commit

Permalink
Merge pull request #2984 from statisticsnorway/develop
Browse files Browse the repository at this point in the history
Deploy to Production
  • Loading branch information
ssb-cgn authored Oct 24, 2024
2 parents fcfdf74 + d7709c1 commit db33b8d
Show file tree
Hide file tree
Showing 12 changed files with 2,452 additions and 1,840 deletions.
2 changes: 1 addition & 1 deletion .github/auto_assign.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ assignees:
- johnnadeluy
# - annesiri
- Carl-OW
- michaelpande
# - michaelpande

# A number of assignees to add to the pull request
# Set to 0 to add all of the assignees.
Expand Down
76 changes: 53 additions & 23 deletions .github/workflows/delete_nais.yaml
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 }}"
Expand All @@ -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
55 changes: 27 additions & 28 deletions .github/workflows/deploy_nais.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 }}"
Expand All @@ -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
Expand All @@ -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
21 changes: 21 additions & 0 deletions backstage.yaml
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
6 changes: 5 additions & 1 deletion docs/Testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,8 @@ In order to bypass Varnish, we will sometimes want to run the tests directly tow
Further improvements and more test coverage might be a useful addition.
- Begin with the [quick start](https://gatling.io/docs/gatling/tutorials/quickstart/) to Gatling
- Refer do the [Cheat sheet](https://gatling.io/docs/gatling/reference/current/cheat-sheet/) and further documentation for reference.
- The Gatling zip package contains useful examples, don't forget to check them out!
- The Gatling zip package contains useful examples, don't forget to check them out!

## Deploying feature branches to Nais
We use a gihub pull request label to ensure we control which branches are deployed to Nais.
Add the branch `nais` to deploy your branch with a minimal set of test content! Maybe it even takes down the branch environment when you close the PR!
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Gradle Project settings
projectName = mimir
version = 2.15.0
version = 2.16.0

# XP App values
appDisplayName = Mimir application
Expand Down
12 changes: 6 additions & 6 deletions nais.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ metadata:
name: mimir-branch-{{branch}}
namespace: ssbno
annotations:
nais.io/read-only-file-system: "false"
nais.io/run-as-user: "1337"
nais.io/read-only-file-system: 'false'
nais.io/run-as-user: '1337'
labels:
team: ssbno
spec:
image: {{ image }}
# image: europe-north1-docker.pkg.dev/nais-management-b3a7/ssbno/ssbno-mimir/mimir:...
image: '{{ image }}'
# image: europe-north1-docker.pkg.dev/nais-management-b3a7/ssbno/ssbno-mimir/mimir:...
# ^--- interpolated from the ${{ env.docker_image }} variable in the action

replicas:
Expand Down Expand Up @@ -39,9 +39,9 @@ spec:
prometheus:
enabled: false

env:
env:
- name: VHOST_HOST
value: ssbno-{{branch}}.external.test.ssb.cloud.nais.io

ingresses:
- https://ssbno-{{branch}}.external.test.ssb.cloud.nais.io # must match vhost
- https://ssbno-{{branch}}.external.test.ssb.cloud.nais.io # must match vhost
Loading

0 comments on commit db33b8d

Please sign in to comment.