Skip to content

Commit

Permalink
Move PR changes to new branch (#287)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hatleskog authored Dec 18, 2024
1 parent c583472 commit 37feec8
Show file tree
Hide file tree
Showing 9 changed files with 447 additions and 40 deletions.
86 changes: 86 additions & 0 deletions .github/workflows/api-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: build completion

on:
push:
branches: ["main"]

workflow_dispatch:
inputs:
environment:
description: 'Environment to deploy to'
required : true
type: choice
default: dev
options:
- dev
- test
- prod

permissions:
id-token: write
contents: read

jobs:
runtests:
uses: ./.github/workflows/runtests.yaml
secrets:
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
with:
deployment: 'runtests'
environment: 'dev'
testPath: './Equinor.ProCoSys.Completion.sln'

build-and-push-docker:
needs: runtests
uses: ./.github/workflows/build-and-push-docker.yaml
secrets:
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
with:
repositoryName: procosys-completion
dockerFilePath: ./src/Dockerfile
environment: dev
version: 1.000.0.${{github.run_id}}

deploy-to-radix:
needs: build-and-push-docker
uses: ./.github/workflows/deploy-to-radix.yaml
secrets:
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
with:
applicationName: procosys-completion-api
componentName: backend
imageTag: 1.000.0.${{github.run_id}}
environment: dev

deploy-to-radix-test:
needs: deploy-to-radix
uses: ./.github/workflows/deploy-to-radix.yaml
secrets:
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
with:
applicationName: procosys-completion-api
componentName: backend
imageTag: 1.000.0.${{github.run_id}}
environment: test

deploy-to-radix-prod:
needs: deploy-to-radix-test
uses: ./.github/workflows/deploy-to-radix.yaml
secrets:
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
with:
applicationName: procosys-completion-api
componentName: backend
imageTag: 1.000.0.${{github.run_id}}
environment: prod
73 changes: 73 additions & 0 deletions .github/workflows/build-and-push-docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Build and push to Azure Container Registry

on:
workflow_call:
inputs:
repositoryName:
description: "Name of the repository within Azure Container Registry"
required: true
type: string
dockerFilePath:
description: "File to the docker path"
required: true
type: string
environment:
description: 'Environment to deploy to'
required: true
type: string
version:
description: 'Deploy version'
required: true
type: string
secrets:
AZURE_CLIENT_ID:
required: true
AZURE_CLIENT_SECRET:
required: true
AZURE_TENANT_ID:
required: true
AZURE_SUBSCRIPTION_ID:
required: true

jobs:
build-and-push-docker:
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
steps:
- uses: actions/checkout@v4
- name: Azure CLI Login
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Login to Azure Container Registry
run: az acr login --name procosys
- name: Get Access Token
run: |
echo "Retrieving access token..."
TOKEN=$(az account get-access-token --resource=https://pkgs.visualstudio.com --query accessToken -o tsv)
echo "FEED_ACCESSTOKEN=$TOKEN" >> $GITHUB_ENV
- name: Verify Access Token
run: |
echo "Access token starts with: $(echo $FEED_ACCESSTOKEN | cut -c1-10)"
echo "Access token length: $(echo -n $FEED_ACCESSTOKEN | wc -c)"
env:
FEED_ACCESSTOKEN: ${{ env.FEED_ACCESSTOKEN }}
- name: Build and push Docker image
env:
DOCKER_BUILDKIT: 1 # Enable BuildKit for this step
uses: docker/build-push-action@v4
with:
context: ./src
file: ${{ inputs.dockerFilePath }}
push: true
build-args: |
FEED_ACCESSTOKEN=${{ env.FEED_ACCESSTOKEN }}
AZURE_CLIENT_ID=${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID=${{ secrets.AZURE_TENANT_ID }}
secrets: |
AZURE_CLIENT_SECRET=${{ secrets.AZURE_CLIENT_SECRET }}
tags: |
procosys.azurecr.io/api/${{ inputs.repositoryName }}:${{ inputs.version }}
procosys.azurecr.io/api/${{ inputs.repositoryName }}:latest
60 changes: 60 additions & 0 deletions .github/workflows/deploy-to-radix.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Build and push to Azure Container Registry

on:
workflow_call:
inputs:
applicationName:
description: "Name of the application within Radix"
required: true
type: string
componentName:
description: "Name of the component within Radix"
required: true
type: string
imageTag:
description: "The tag of the built Docker image"
required: true
type: string
environment:
description: 'Environment to deploy to'
required: true
type: string
secrets:
AZURE_CLIENT_ID:
required: true
AZURE_TENANT_ID:
required: true
AZURE_SUBSCRIPTION_ID:
required: true

jobs:
deploy-to-radix:
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
steps:
- uses: actions/checkout@v4
- name: Azure CLI Login
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
# Radix
- name: 'Get Azure principal token for Radix'
run: |
token=$(az account get-access-token --resource 6dae42f8-4368-4678-94ff-3960e28e3630 --query=accessToken -otsv)
echo "::add-mask::$token"
echo "APP_SERVICE_ACCOUNT_TOKEN=$token" >> $GITHUB_ENV
- name: Deploy on Radix
uses: equinor/radix-github-actions@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
args: >
create pipeline-job
deploy
-a ${{ inputs.applicationName }}
--from-config
-e ${{ inputs.environment }}
--component ${{ inputs.componentName }}
--image-tag-name ${{ inputs.componentName }}=${{ inputs.imageTag }}
-f
80 changes: 80 additions & 0 deletions .github/workflows/runtests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Test and Deploy

on:
workflow_call:
inputs:
deployment:
description: 'Deployment type'
required: false
type: string
environment:
description: 'Target environment'
required: true
type: string
testPath:
description: 'Path to the test project'
required: true
type: string
secrets:
AZURE_CLIENT_ID:
required: true
AZURE_TENANT_ID:
required: true
AZURE_SUBSCRIPTION_ID:
required: true

jobs:
runtests:
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
steps:
- uses: actions/checkout@v4
- name: Azure CLI Login
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Azure CLI script
uses: azure/cli@v2
with:
azcliversion: latest
inlineScript: |
az account show
# You can write your Azure CLI inline scripts here.
- name: Get Access Token
run: |
echo "Retrieving access token..."
TOKEN=$(az account get-access-token --resource=https://pkgs.visualstudio.com --query accessToken -o tsv)
echo "FEED_ACCESSTOKEN=$TOKEN" >> $GITHUB_ENV
- name: Setup dotnet 8
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Install dotnet ef
run: dotnet tool install -g dotnet-ef
- name: Configure NuGet source
run: |
dotnet nuget add source --name ProCoSysOfficial \
--username statoildeveloper \
--password ${{ env.FEED_ACCESSTOKEN }} \
--store-password-in-clear-text \
https://statoildeveloper.pkgs.visualstudio.com/_packaging/ProCoSysOfficial/nuget/v3/index.json
- name: Run tests
run: |
cd src/
dotnet test ${{ inputs.testPath }} -c Release --logger "trx"
env:
DOTNET_NOLOGO: true

- name: Publish Test Results
uses: actions/upload-artifact@v3
with:
name: TestResults
path: '**/*.trx'

- name: Deploy
run: |
echo "Deploying to ${{ inputs.environment }}"
echo "Using deployment type: ${{ inputs.deployment }}"
13 changes: 9 additions & 4 deletions radixconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,25 @@ kind: RadixApplication
metadata:
name: procosys-completion-api
spec:
privateImageHubs:
procosys.azurecr.io:
username: radix-pcs-completion
environments:
- name: dev
- name: test
- name: prod

components:
- name: backend
image: procosys.azurecr.io/completion/api:{imageTagName}
image: procosys.azurecr.io/api/procosys-completion:{imageTagName}
ports:
- name: http
port: 5000
publicPort: http
secrets:
- CONNECTIONSTRINGS__APPCONFIG
#- FEED_ACCESSTOKEN
- DB_CONNECTION_STRING
environmentConfig:
# Development environment
- environment: dev
Expand Down Expand Up @@ -76,6 +81,6 @@ spec:
# ...equinor-procosys-devops-docker-registry with ...
# ...permission to puch to procosys.azurecr.io container registry
#-------------------------------------------------------
privateImageHubs:
procosys.azurecr.io:
username: 9d3898e4-730f-4fb5-8ddf-a5de51537896
# privateImageHubs:
# procosys.azurecr.io:
# username: 9d3898e4-730f-4fb5-8ddf-a5de51537896
Loading

0 comments on commit 37feec8

Please sign in to comment.