Merge pull request #27 from ts4nfdi/refacotor/generlize-federation-ca… #23
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: Continuous Integration | |
on: | |
push: | |
branches: | |
- "main" | |
tags: | |
- "*" | |
env: | |
KUBECONFIG: .kube/config | |
KUBECONFIG_FILE: ${{ secrets.KUBECONFIG }} | |
jobs: | |
build: | |
name: "Build Image" | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- id: generate-image-tag | |
name: Generate Image Tag | |
run: | | |
head_ref="${GITHUB_HEAD_REF//\//-}" | |
ref_name="${head_ref:-${GITHUB_REF_NAME/main/latest}}" | |
echo "imageTag=${ref_name#v}" >> $GITHUB_ENV | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up JDK | |
uses: actions/setup-java@v2 | |
with: | |
distribution: 'temurin' | |
java-version: '11' | |
- name: Run tests | |
run: mvn test | |
- name: Build with Maven | |
run: mvn clean package | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build and push | |
uses: docker/build-push-action@v5 | |
with: | |
context: ./ | |
file: ./Dockerfile | |
push: true | |
tags: | | |
ghcr.io/${{ github.repository }}:${{ env.imageTag }} | |
ghcr.io/${{ github.repository }}:${{ github.event.pull_request.head.sha || github.sha }} | |
deploy_main: | |
needs: build | |
if: github.ref == 'refs/heads/main' | |
runs-on: ubuntu-latest | |
steps: | |
- id: generate-image-tag | |
name: Generate Image Tag | |
run: | | |
head_ref="${GITHUB_HEAD_REF//\//-}" | |
ref_name="${head_ref:-${GITHUB_REF_NAME/main/latest}}" | |
echo "imageTag=${ref_name#v}" >> $GITHUB_ENV | |
- uses: actions/checkout@v2 | |
- name: Set up Kubernetes config | |
run: | | |
mkdir -p .kube | |
echo "${{ secrets.KUBECONFIG }}" > $KUBECONFIG | |
- name: Create Kubernetes secret for ONTOPORTAL_APIKEY | |
run: | | |
kubectl create secret generic ontoportal-secret \ | |
--from-literal=ONTOPORTAL_APIKEY=${{ secrets.ONTOPORTAL_APIKEY }} \ | |
--namespace='ts4nfdi' \ | |
--dry-run=client -o yaml | kubectl apply -f - | |
- name: Deploy to Kubernetes | |
uses: stefanprodan/kube-tools@v1 | |
with: | |
helmv3: 3.12.0 | |
command: | | |
kubectl get nodes | |
helmv3 repo add api-gateway-deployment https://ts4nfdi.github.io/api-gateway-deployment/ | |
helmv3 repo update | |
helmv3 upgrade ts4nfdi \ | |
--install \ | |
--namespace='ts4nfdi' \ | |
--set-json='ingress.dns="ts4nfdi-api-gateway.prod.km.k8s.zbmed.de"' \ | |
--set-json='images.frontend="ghcr.io/${{ github.repository }}:${{ github.event.pull_request.head.sha || github.sha }}"' \ | |
--set-json='ingress.enableSSL="true"' \ | |
--set-json='ingress.certIssuer="letsencrypt-prod"' \ | |
api-gateway-deployment/api-gateway |