Deploy #142
Workflow file for this run
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
name: Deploy | |
on: | |
workflow_dispatch: | |
inputs: | |
environment: | |
description: 'Miljø (q1, q2 eller prod)' | |
required: true | |
default: 'q2' | |
permissions: | |
contents: write | |
packages: write | |
env: | |
IMAGE: docker.pkg.github.com/${{ github.repository }}/melosys-eessi:${{ github.sha }} | |
IMAGE_MANIFEST: https://docker.pkg.github.com/v2/${{ github.repository }}/melosys-eessi/manifests/${{ github.sha }} | |
jobs: | |
check_docker_image_exists: | |
name: Check if docker image exists in registry | |
runs-on: ubuntu-latest | |
steps: | |
- run: | | |
echo "DOCKER_IMAGE_EXISTS_HTTP_STATUS=$(curl -X GET -s -o /dev/null -w "%{http_code}" ${{ env.IMAGE_MANIFEST }} -u ${{ github.actor }}:${{ secrets.GITHUB_TOKEN }})" >> $GITHUB_ENV | |
- id: set_output | |
run: | | |
if [ ${{ env.DOCKER_IMAGE_EXISTS_HTTP_STATUS }} -eq 200 ] | |
then | |
echo "::set-output name=exists::true" | |
else | |
echo "::set-output name=exists::false" | |
fi | |
outputs: | |
exists: ${{ steps.set_output.outputs.exists }} | |
build: | |
runs-on: ubuntu-latest | |
needs: check_docker_image_exists | |
if: needs.check_docker_image_exists.outputs.exists != 'true' | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Setup Maven | |
uses: actions/cache@v4 | |
with: | |
path: ~/.m2/repository | |
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} | |
restore-keys: | | |
${{ runner.os }}-maven- | |
- name: Test and build | |
run: mvn clean package -B -e -U -DskipTests | |
- name: Build docker image | |
run: | | |
docker build -t ${IMAGE} . | |
- name: Login to Github Package Registry | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
docker login docker.pkg.github.com -u ${GITHUB_REPOSITORY} -p ${GITHUB_TOKEN} | |
- name: Push Docker image | |
run: | | |
docker push ${IMAGE} | |
# Deploy til dev (Q2) manuelt | |
deploy_dev: | |
name: Deploy til Q2 | |
needs: build | |
if: always() && (needs.build.result == 'success' || needs.build.result == 'skipped') && (github.event.inputs.environment == 'dev' || github.event.inputs.environment == 'q2') | |
runs-on: ubuntu-latest | |
environment: dev-fss-q2:teammelosys | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: deploy new Unleash Apikey to ${{github.event.inputs.environment}} | |
uses: nais/deploy/actions/deploy@v1 | |
env: | |
APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }} | |
CLUSTER: dev-fss | |
RESOURCE: nais/unleash-apitoken.yml | |
VARS: nais/vars-q2.json | |
- name: Deploy | |
uses: nais/deploy/actions/deploy@v1 | |
env: | |
APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }} | |
CLUSTER: dev-fss | |
RESOURCE: nais/nais.yml | |
VARS: nais/vars-q2.json | |
- run: | | |
echo "COMMIT_MSG=$(git log --format=%s -n 1)" >> $GITHUB_ENV | |
- name: Slack Notification (deploy success) | |
if: success() | |
uses: rtCamp/[email protected] | |
env: | |
SLACK_COLOR: good | |
SLACK_USERNAME: Github Actions | |
SLACK_ICON: https://github.com/github.png?size=48 | |
SLACK_TITLE: ':clap: melosys-eessi ble manuelt deployet til dev :rocket:' | |
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} | |
SLACK_MESSAGE: ${{ env.COMMIT_MSG }} | |
- name: Slack Notification (deploy failure) | |
if: failure() | |
uses: rtCamp/[email protected] | |
env: | |
SLACK_COLOR: danger | |
SLACK_USERNAME: Github Actions | |
SLACK_ICON: https://github.com/github.png?size=48 | |
SLACK_TITLE: ':crying_cat_face: melosys-eessi kunne ikke manuelt deployes til dev!' | |
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} | |
SLACK_MESSAGE: ${{ env.COMMIT_MSG }} | |
# Deploy til Q1 manuelt | |
deploy_q1: | |
name: Deploy til Q1 | |
needs: build | |
if: always() && (needs.build.result == 'success' || needs.build.result == 'skipped') && github.event.inputs.environment == 'q1' | |
runs-on: ubuntu-latest | |
environment: dev-fss-q1:teammelosys | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: deploy new Unleash Apikey to ${{github.event.inputs.environment}} | |
uses: nais/deploy/actions/deploy@v1 | |
env: | |
APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }} | |
CLUSTER: dev-fss | |
RESOURCE: nais/unleash-apitoken.yml | |
VARS: nais/vars-q1.json | |
- name: Deploy | |
uses: nais/deploy/actions/deploy@v1 | |
env: | |
APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }} | |
CLUSTER: dev-fss | |
RESOURCE: nais/nais.yml | |
VARS: nais/vars-q1.json | |
- run: | | |
echo "COMMIT_MSG=$(git log --format=%s -n 1)" >> $GITHUB_ENV | |
- name: Slack Notification (deploy success) | |
if: success() | |
uses: rtCamp/[email protected] | |
env: | |
SLACK_COLOR: good | |
SLACK_USERNAME: Github Actions | |
SLACK_ICON: https://github.com/github.png?size=48 | |
SLACK_TITLE: ':clap: melosys-eessi ble manuelt deployet til q1 :rocket:' | |
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} | |
SLACK_MESSAGE: ${{ env.COMMIT_MSG }} | |
- name: Slack Notification (deploy failure) | |
if: failure() | |
uses: rtCamp/[email protected] | |
env: | |
SLACK_COLOR: danger | |
SLACK_USERNAME: Github Actions | |
SLACK_ICON: https://github.com/github.png?size=48 | |
SLACK_TITLE: ':crying_cat_face: melosys-eessi kunne ikke manuelt deployes til q1!' | |
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} | |
SLACK_MESSAGE: ${{ env.COMMIT_MSG }} | |
# Deploy til prod manuelt | |
deploy_prod: | |
name: Deploy til prod | |
needs: build | |
if: always() && (needs.build.result == 'success' || needs.build.result == 'skipped') && github.event.inputs.environment == 'prod' | |
runs-on: ubuntu-latest | |
environment: prod-fss:teammelosys | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: deploy new Unleash Apikey to ${{github.event.inputs.environment}} | |
uses: nais/deploy/actions/deploy@v1 | |
env: | |
APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }} | |
CLUSTER: prod-fss | |
RESOURCE: nais/unleash-apitoken.yml | |
VARS: nais/vars-prod.json | |
- name: Deploy | |
uses: nais/deploy/actions/deploy@v1 | |
env: | |
APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }} | |
CLUSTER: prod-fss | |
RESOURCE: nais/nais.yml | |
VARS: nais/vars-prod.json | |
- run: | | |
echo "COMMIT_MSG=$(git log --format=%s -n 1)" >> $GITHUB_ENV | |
- name: Slack Notification (deploy success) | |
if: success() | |
uses: rtCamp/[email protected] | |
env: | |
SLACK_COLOR: good | |
SLACK_USERNAME: Github Actions | |
SLACK_ICON: https://github.com/github.png?size=48 | |
SLACK_TITLE: ':clap: melosys-eessi ble manuelt deployet til prod :rocket:' | |
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} | |
SLACK_MESSAGE: ${{ env.COMMIT_MSG }} | |
- name: Slack Notification (deploy failure) | |
if: failure() | |
uses: rtCamp/[email protected] | |
env: | |
SLACK_COLOR: danger | |
SLACK_USERNAME: Github Actions | |
SLACK_ICON: https://github.com/github.png?size=48 | |
SLACK_TITLE: ':crying_cat_face: melosys-eessi kunne ikke manuelt deployes til prod!' | |
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} | |
SLACK_MESSAGE: ${{ env.COMMIT_MSG }} |