diff --git a/.github/workflows/api-build.yaml b/.github/workflows/api-build.yaml index de47e90f..93b86eae 100644 --- a/.github/workflows/api-build.yaml +++ b/.github/workflows/api-build.yaml @@ -21,17 +21,17 @@ permissions: contents: read jobs: - runtests: - uses: equinor/procosys-completion-api/.github/workflows/runtests.yaml@github-action-pipeline - secrets: - AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} - AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} - AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - AZURE_ARTIFACTS_PAT: ${{ secrets.AZURE_ARTIFACTS_PAT }} - with: - deployment: 'runtests' - environment: 'dev' - testPath: './Equinor.ProCoSys.Completion.sln' + # runtests: + # uses: equinor/procosys-completion-api/.github/workflows/runtests.yaml@github-action-pipeline + # secrets: + # AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} + # AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} + # AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + # AZURE_ARTIFACTS_PAT: ${{ secrets.AZURE_ARTIFACTS_PAT }} + # with: + # deployment: 'runtests' + # environment: 'dev' + # testPath: './Equinor.ProCoSys.Completion.sln' # build-and-push-docker: # needs: runtests @@ -62,3 +62,18 @@ jobs: # componentName: backend # imageTag: 1.000.0.${{github.run_id}} # environment: dev + + migrate-dev: + #needs: build-and-push-docker + uses: equinor/procosys-completion-api/.github/workflows/migrate-bundle.yaml@github-action-pipeline + secrets: + AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }} + AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }} + AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + DB_CONNECTION_STRING: ${{ secrets.DB_CONNECTION_STRING }} + AZURE_ARTIFACTS_PAT: ${{ secrets.AZURE_ARTIFACTS_PAT }} + with: + workingDirectory: ./src/Equinor.ProCoSys.Completion.Infrastructure + bundleDirectory: ../Equinor.ProCoSys.Completion.WebApi + contextName: CompletionContext + environment: dev \ No newline at end of file diff --git a/.github/workflows/migrate-bundle.yaml b/.github/workflows/migrate-bundle.yaml new file mode 100644 index 00000000..038c8ea1 --- /dev/null +++ b/.github/workflows/migrate-bundle.yaml @@ -0,0 +1,100 @@ +name: "🛠️ Migration Bundle" + +on: + workflow_call: + inputs: + workingDirectory: + description: "Path for the working directory of the project" + required: true + type: string + bundleDirectory: + description: "Path for the bundle directory" + required: true + type: string + contextName: + description: "Context name for the project/component" + 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 + DB_CONNECTION_STRING: + required: true + AZURE_ARTIFACTS_PAT: + required: true + +jobs: + migrate-dev: + 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: 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 + + # Step 3: Configure NuGet source with access token + - name: Configure NuGet source + run: | + dotnet nuget add source --name ProCoSysOfficial \ + --username statoildeveloper \ + --password ${{ secrets.AZURE_ARTIFACTS_PAT }} \ + --store-password-in-clear-text \ + https://statoildeveloper.pkgs.visualstudio.com/_packaging/ProCoSysOfficial/nuget/v3/index.json + + - name: create migrations bundle + id: bundle + working-directory: ${{ inputs.workingDirectory }} + run: Global__UseAzureAppConfig="false" FEED_ACCESSTOKEN=${{ secrets.AZURE_ARTIFACTS_PAT }} dotnet ef migrations bundle --self-contained --runtime linux-x64 -s ${{ inputs.bundleDirectory }} --context ${{ inputs.contextName }} -o bundle.exe --verbose + - name: Copy appsettings.json + working-directory: ${{ inputs.workingDirectory }} + run: cp ${{ inputs.bundleDirectory }}/appsettings.json . + + - name: Add GitHub Actions IP to Azure SQL Server Firewall + run: | + github_ip_ranges=$(curl -s https://api.github.com/meta | jq -r '.actions[]') + for ip in $github_ip_ranges; do + az sql server firewall-rule create \ + --resource-group rg-pcs5-completion-dev \ + --server sql-pcs5-completion-dev \ + --name GitHubActionsAccess \ + --start-ip-address $ip \ + --end-ip-address $ip + done + + - name: Run bundle + working-directory: ${{ inputs.workingDirectory }} + run: ./bundle.exe --connection ${{ secrets.DB_CONNECTION_STRING }} + env: + DB_CONNECTION_STRING: ${{ secrets.DB_CONNECTION_STRING }} + + - name: Remove GitHub Actions IP from Firewall + run: | + az sql server firewall-rule delete \ + --resource-group rg-pcs5-completion-dev \ + --server sql-pcs5-completion-dev \ + --name GitHubActionsAccess \ No newline at end of file