Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release #42

Merged
merged 11 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 69 additions & 45 deletions .github/workflows/build-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,79 @@ on:
branches: [ main, release ]

permissions:
actions: read
checks: read
contents: read
deployments: read
id-token: write
issues: read
discussions: read
packages: read
pages: read
pull-requests: read
repository-projects: read
security-events: read
statuses: read
contents: read

jobs:
get-target-configs:
name: Get target configs for branch
outputs:
target_configs: ${{ steps.get-target-configs.outputs.target_configs }}
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Get target configs
id: get-target-configs
run: |
configs=$(ls $GITHUB_WORKSPACE/.github/workflows/config/${GITHUB_REF_NAME} | jq -Rsc '. / "\n" - [""]')
echo "target_configs=${configs}" >> $GITHUB_OUTPUT

build-deploy-image:
name: Build & push
build-deploy:
runs-on: ubuntu-20.04
needs:
- get-target-configs
strategy:
fail-fast: false
matrix:
config: ${{ fromJson(needs.get-target-configs.outputs.target_configs) }}
matrix:
target:
- name: "dev"
ref: "refs/heads/main"
acr-name: "radixdev"
client-id: "1a292b18-2960-49a5-b429-c8a50349b5eb"
subscription-id: "16ede44b-1f74-40a5-b428-46cca9a5741b"

- name: "playground"
ref: "refs/heads/release"
acr-name: "radixdev"
client-id: "1a292b18-2960-49a5-b429-c8a50349b5eb"
subscription-id: "16ede44b-1f74-40a5-b428-46cca9a5741b"

- name: "platform"
ref: "refs/heads/release"
acr-name: "radixprod"
client-id: "d1ee58e8-5896-48d9-a777-5418c3df9a58"
subscription-id: "ded7ca41-37c8-4085-862f-b11d21ab341a"

- name: "c2"
ref: "refs/heads/release"
acr-name: "radixc2prod"
client-id: "d1ee58e8-5896-48d9-a777-5418c3df9a58"
subscription-id: "ded7ca41-37c8-4085-862f-b11d21ab341a"

steps:
- uses: actions/checkout@v3
- name: Persist environment from ${{ matrix.config }} across steps
run: |
$GITHUB_WORKSPACE/.github/workflows/scripts/persist-env.sh ${{ matrix.config }}

- uses: azure/login@v1
with:
client-id: ${{ env.AZURE_CLIENT_ID }}
tenant-id: ${{ env.AZURE_TENANT_ID }}
subscription-id: ${{ env.AZURE_SUBSCRIPTION_ID }}

- name: Build image
run: |
$GITHUB_WORKSPACE/.github/workflows/scripts/build-push.sh
- uses: actions/checkout@v4
if: matrix.target.ref == github.ref

- uses: azure/login@v1
if: matrix.target.ref == github.ref
with:
client-id: ${{matrix.target.client-id}}
tenant-id: "3aa4a235-b6e2-48d5-9195-7fcf05b459b0"
subscription-id: ${{matrix.target.subscription-id}}

- name: Generate image tag
if: matrix.target.ref == github.ref
id: tag
run: |
sha=${GITHUB_SHA::8}
ts=$(date +%s)
echo "tag=${GITHUB_REF_NAME}-${sha}-${ts}" >> $GITHUB_OUTPUT

- name: Build image
if: matrix.target.ref == github.ref
env:
AZURE_SUBSCRIPTION_ID: ${{matrix.target.subscription-id}}
ACR_NAME: ${{matrix.target.acr-name}}
IMAGE_NAME: radix-vulnerability-scanner
TAG: ${{steps.tag.outputs.tag}}
run: |
az acr task run \
--subscription ${AZURE_SUBSCRIPTION_ID} \
--name radix-image-builder-internal \
--registry ${ACR_NAME} \
--context ${GITHUB_WORKSPACE} \
--file ${GITHUB_WORKSPACE}/Dockerfile \
--set DOCKER_REGISTRY=${ACR_NAME} \
--set BRANCH=${GITHUB_REF_NAME} \
--set TAGS="--tag ${ACR_NAME}.azurecr.io/${IMAGE_NAME}:${TAG}" \
--set DOCKER_FILE_NAME=Dockerfile \
--set PUSH="--push" \
--set REPOSITORY_NAME=${IMAGE_NAME} \
--set CACHE="" \
--set CACHE_TO_OPTIONS="--cache-to=type=registry,ref=${ACR_NAME}.azurecr.io/${IMAGE_NAME}:radix-cache-${GITHUB_REF_NAME},mode=max"

7 changes: 0 additions & 7 deletions .github/workflows/config/common.cfg

This file was deleted.

12 changes: 0 additions & 12 deletions .github/workflows/config/main/dev.cfg

This file was deleted.

12 changes: 0 additions & 12 deletions .github/workflows/config/release/c2.cfg

This file was deleted.

12 changes: 0 additions & 12 deletions .github/workflows/config/release/playground.cfg

This file was deleted.

12 changes: 0 additions & 12 deletions .github/workflows/config/release/prod.cfg

This file was deleted.

140 changes: 73 additions & 67 deletions .github/workflows/deploy-database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,85 +3,91 @@ name: Deploy Database
on:
push:
branches: [main, release]
workflow_dispatch:

permissions:
actions: read
checks: read
contents: read
deployments: read
id-token: write
issues: read
discussions: read
packages: read
pages: read
pull-requests: read
repository-projects: read
security-events: read
statuses: read
contents: read

jobs:
get-target-configs:
name: Get target configs for branch
outputs:
target_configs: ${{ steps.get-target-configs.outputs.target_configs }}
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Get target configs
id: get-target-configs
run: |
configs=$(ls $GITHUB_WORKSPACE/.github/workflows/config/${GITHUB_REF_NAME} | jq -Rsc '. / "\n" - [""]')
echo "target_configs=${configs}" >> $GITHUB_OUTPUT

deploy-sql-server:
deploy:
runs-on: ubuntu-20.04
needs:
- get-target-configs
strategy:
fail-fast: false
matrix:
config: ${{ fromJson(needs.get-target-configs.outputs.target_configs) }}
matrix:
target:
- name: "dev"
ref: "refs/heads/main"
client-id: "a23b30b8-3faa-42a1-817e-6cd097a620f1"
server: "sql-radix-vulnerability-scan-dev.database.windows.net"

- name: "playground"
ref: "refs/heads/release"
client-id: "453fb3de-daaa-43e6-93ef-a470849a2b6b"
server: "sql-radix-vulnerability-scan-playground.database.windows.net"

- name: "platform"
ref: "refs/heads/release"
client-id: "50e78187-ff60-49c5-bcbe-701bbbf4f5d7"
server: "sql-radix-vulnerability-scan-platform.database.windows.net"

- name: "c2"
ref: "refs/heads/release"
client-id: "f26240e2-3095-4273-8559-2ca9a121991e"
server: "sql-radix-vulnerability-scan-c2-prod.database.windows.net"

env:
connection: >-
Server=${{matrix.target.server}};
Initial Catalog=radix-vulnerability-scan;
Authentication=Active Directory Default;
Encrypt=True;
TrustServerCertificate=False;
Connection Timeout=30;

steps:
- uses: actions/checkout@v3
- name: Persist environment from ${{ matrix.config }} across steps
run: |
$GITHUB_WORKSPACE/.github/workflows/scripts/persist-env.sh ${{ matrix.config }}
- uses: actions/checkout@v4
if: matrix.target.ref == github.ref

- uses: azure/login@v1
if: matrix.target.ref == github.ref
with:
client-id: ${{matrix.target.client-id}}
tenant-id: "3aa4a235-b6e2-48d5-9195-7fcf05b459b0"
allow-no-subscriptions: true

- uses: azure/login@v1
with:
client-id: ${{ env.AZURE_CLIENT_ID }}
tenant-id: ${{ env.AZURE_TENANT_ID }}
subscription-id: ${{ env.AZURE_SUBSCRIPTION_ID }}
- uses: azure/[email protected]
if: matrix.target.ref == github.ref
with:
connection-string: ${{env.connection}}
path: './azure-infrastructure/sql-scripts/predeploy.sql'

- name: Get DB password from KV
run: |
db_admin_pw=$(az keyvault secret show --id https://${KEY_VAULT_NAME}.vault.azure.net/secrets/${DB_ADMIN_SECRET_NAME} --query value --output tsv)
echo "::add-mask::$db_admin_pw"
echo "DB_ADMIN_PASSWORD=$db_admin_pw" >> $GITHUB_ENV
- uses: azure/[email protected]
if: matrix.target.ref == github.ref
with:
connection-string: ${{env.connection}}
path: './azure-infrastructure/sql-scripts/roles.sql'

- name: Generate random firewall rule name
run: |
fw_rule_name="github-runner-$(uuidgen)"
echo "FIREWALL_RULE_NAME=$fw_rule_name" >> $GITHUB_ENV

- name: Install SqlServer PS module
shell: pwsh
run: |
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted
Install-Module -Name SqlServer
- uses: azure/[email protected]
if: matrix.target.ref == github.ref
with:
connection-string: ${{env.connection}}
path: './azure-infrastructure/sql-scripts/types.sql'

- name: Whitelist Runner IP in firewalls
shell: pwsh
run: |
./.github/workflows/scripts/whitelist-ip.ps1 -FirewallRuleName "${env:FIREWALL_RULE_NAME}"
- uses: azure/[email protected]
if: matrix.target.ref == github.ref
with:
connection-string: ${{env.connection}}
path: './azure-infrastructure/sql-scripts/tables.sql'

- name: Creating DB schema and tables
shell: pwsh
run: |
./.github/workflows/scripts/create-db.ps1
- uses: azure/[email protected]
if: matrix.target.ref == github.ref
with:
connection-string: ${{env.connection}}
path: './azure-infrastructure/sql-scripts/views.sql'

- name: Blacklist Runner IP in firewalls
shell: pwsh
if: ${{ always() }}
run: |
./.github/workflows/scripts/blacklist-ip.ps1 -FirewallRuleName "${env:FIREWALL_RULE_NAME}"
- uses: azure/[email protected]
if: matrix.target.ref == github.ref
with:
connection-string: ${{env.connection}}
path: './azure-infrastructure/sql-scripts/procedures.sql'
35 changes: 33 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,45 @@ on:
pull_request:
branches:
- main

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Build docker image
env:
REF: ${{ github. sha }}
run: make build


lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Install dependencies
run: go mod download
- name: Install GolangCI Lint
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.55.2

- name: golangci-lint
run: golangci-lint run --timeout=30m --max-same-issues=0 --out-format=github-actions

test:
name: Unit Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Install dependencies
run: go mod download
- name: Run Tests
run: go test -cover `go list ./... | grep -v 'pkg/client'`
Loading
Loading