Skip to content

Update CorsExtension.cs #8

Update CorsExtension.cs

Update CorsExtension.cs #8

Workflow file for this run

on:
push:
branches:
- main
- development
- qa
- staging
jobs:
deploy:
runs-on: self-hosted
env:
DOTNET_VERSION: 8.x.x
DOTNET_SRC: ./
NEXUS_SOURCE: https://hubrepopanda.pandatech.it/repository/nuget-hosted/index.json
NUGET_SOURCE: https://api.nuget.org/v3/index.json
DOCKER_REPO_BASE: repopanda.pandatech.it/pandatech/repository/pandatech
SERVICE_NAME: ${{ github.event.repository.name }}
K8S_NAMESPACE: ${{
(github.ref == 'refs/heads/staging' && 'staging') ||
(github.ref == 'refs/heads/qa' && 'qa') ||
(github.ref == 'refs/heads/development' && 'dev')
}}
#(github.ref == 'refs/heads/main' && 'production') ||
K8S_CLUSTER_ADDRESS: https://10.0.8.11:6443
DOTNET_INSTALL_DIR: $HOME/dotnet
steps:
- uses: actions/checkout@v3
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
include-prerelease: false
dotnet-install-dir: ${{ env.DOTNET_INSTALL_DIR }}
- name: remove old nuget sources
run: |
dotnet nuget remove source pandatech
dotnet nuget remove source nuget.org
continue-on-error: true
- name: Add local nuget source
run: |
dotnet nuget add source ${{ env.NEXUS_SOURCE }} -n pandatech -u ${{ secrets.nexus_username }} -p ${{ secrets.nexus_password }} --store-password-in-clear-text
continue-on-error: true
- name: Add NuGet.org source
run: |
dotnet nuget add source ${{ env.NUGET_SOURCE }} -n nuget.org
continue-on-error: true
- name: Restore
run: dotnet restore ${{env.DOTNET_SRC}} --verbosity normal --no-cache --force --disable-parallel
- name: Build
run: dotnet build ${{env.DOTNET_SRC}} --no-restore --verbosity normal --configuration Release
- name: Publish
run: dotnet publish ${{env.DOTNET_SRC}} --no-build --verbosity normal --configuration Release --output ./publish
- name: Set DOCKER_TAG
run: echo "DOCKER_TAG=$(date +'%Y%m%d%H%M%S')-$GITHUB_RUN_NUMBER" >> $GITHUB_ENV
- name: Display DOCKER_TAG
run: echo "DOCKER_TAG=${{ env.DOCKER_TAG }}"
- name: Set DOCKER_REPO_PATH
run: |
if [ "${{ github.event_name }}" == "push" ] && [ "${{ startsWith(github.ref, 'refs/heads/') }}" == "true" ]; then
if [ "${{ github.ref }}" == "refs/heads/main" ]; then
DOCKER_REPO_PATH="prod"
elif [ "${{ github.ref }}" == "refs/heads/development" ]; then
DOCKER_REPO_PATH="dev"
else
DOCKER_REPO_PATH=$(echo "${{ github.ref }}" | sed 's#^refs/heads/##')
fi
else
DOCKER_REPO_PATH="unknown-branch"
fi
echo "DOCKER_REPO_PATH=${DOCKER_REPO_PATH}" >> $GITHUB_ENV
- name: Display DOCKER_REPO_PATH
run: echo "DOCKER_REPO_PATH=${{ env.DOCKER_REPO_PATH }}"
- name: Build Docker Image
run: |
DOCKER_TAG=$(date +'%Y%m%d%H%M%S')-$GITHUB_RUN_NUMBER
DOCKER_REPO_BASE=repopanda.pandatech.it/pandatech/repository/pandatech
DOCKER_REPO_PATH=${{ env.DOCKER_REPO_PATH }}
if [ "${{ env.DOCKER_REPO_PATH }}" == "main" ]; then
DOCKER_REPO=${DOCKER_REPO_BASE}/prod
elif [ "${{ env.DOCKER_REPO_PATH }}" == "development" ]; then
DOCKER_REPO=${DOCKER_REPO_BASE}/dev
else
DOCKER_REPO=${DOCKER_REPO_BASE}/${DOCKER_REPO_PATH}
fi
docker build . -t $DOCKER_REPO/${{ env.SERVICE_NAME }}:${DOCKER_TAG} -t $DOCKER_REPO/${{ env.SERVICE_NAME }}:latest
- name: Display Docker Image Tags
run: docker images $DOCKER_REPO/${{ env.SERVICE_NAME }}
- name: Login to Nexus
run: docker login ${{ env.DOCKER_REPO_BASE }} -u ${{ secrets.nexus_username }} -p ${{ secrets.nexus_password }}
- name: Push Docker Image to Nexus
run: |
DOCKER_TAG=${{ env.DOCKER_TAG }}
DOCKER_REPO=${DOCKER_REPO_BASE}/${DOCKER_REPO_PATH}
docker push "${DOCKER_REPO}/${SERVICE_NAME}:${DOCKER_TAG}"
docker push "${DOCKER_REPO}/${SERVICE_NAME}:latest"
- name: Update Deployment
if: github.ref != 'refs/heads/main'
run: |
export KUBECONFIG=/home/runner/.kube/config
sed -i "s|namespace: .*|namespace: ${{ env.K8S_NAMESPACE }}|g" ./kubernetes/deployment.yaml
sed -i "s|${{ env.DOCKER_REPO }}/${{ env.SERVICE_NAME }}:IMAGE_TAG_PLACEHOLDER|${{ env.DOCKER_REPO }}/${{ env.SERVICE_NAME }}:${{ env.DOCKER_TAG }}|g" ./kubernetes/deployment.yaml
sed -i "s|namespace: .*|namespace: ${{ env.K8S_NAMESPACE }}|g" ./kubernetes/service.yaml
sed -i "s|namespace: .*|namespace: ${{ env.K8S_NAMESPACE }}|g" ./kubernetes/ingress.yaml
kubectl apply -f ./kubernetes/deployment.yaml -n ${{ env.K8S_NAMESPACE }}
env:
DOCKER_TAG: ${{ env.DOCKER_TAG }}
K8S_CLUSTER_ADDRESS: ${{ env.K8S_CLUSTER_ADDRESS }}
- name: 'Cleanup build folder'
run: |
ls -la ./
rm -rf ./* || true
rm -rf ./.??* || true
ls -la ./