-
Notifications
You must be signed in to change notification settings - Fork 0
100 lines (82 loc) · 2.48 KB
/
test-and-push.yaml
File metadata and controls
100 lines (82 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
---
name: CI Pipeline
on:
push:
branches:
- main
pull_request:
types:
- 'opened'
- 'synchronize'
- 'reopened'
env:
GO_VERSION: 1.24
KIND_VERSION: v0.27.0
IMAGE_NAME: namespace-cleaner:test
REGISTRY: k8scc01covidacr.azurecr.io
jobs:
deploy-namespace-cleaner: # Consolidated job for all deployment-related tasks
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
# --- Linting and Setup ---
- uses: actions/checkout@v4
- name: Lint Dockerfile
uses: hadolint/hadolint-action@v3.1.0
with:
dockerfile: Dockerfile
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Run yamllint
run: |
pip install yamllint
yamllint .
# --- Build Docker Image ---
- name: Build Docker Image
run: docker build -t ${{ env.IMAGE_NAME }} .
# --- Unit Tests ---
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
- name: Run Unit Tests
run: make test-unit
id: unit-tests
# --- Integration Tests with Kind ---
- name: Install kubectl
uses: azure/setup-kubectl@v3
- name: Install Kind
run: |
curl -Lo ./kind https://kind.sigs.k8s.io/dl/${{ env.KIND_VERSION }}/kind-linux-amd64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind
- name: Create Kind Cluster
run: kind create cluster
- name: Load Image into Kind
run: kind load docker-image ${{ env.IMAGE_NAME }}
- name: Run Integration Tests
run: make test-integration
# --- Security Scan ---
- name: Run Trivy Security Scan
uses: aquasecurity/trivy-action@master
with:
image-ref: ${{ env.IMAGE_NAME }}
severity: "CRITICAL"
ignore-unfixed: true
exit-code: 1
format: table
# --- Push Image to ACR ---
- name: Login to ACR
uses: azure/docker-login@v1
with:
login-server: ${{ env.REGISTRY }}
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Tag and Push Image
run: |
docker tag ${{ env.IMAGE_NAME }} ${{ env.REGISTRY }}/namespace-cleaner:${{ github.sha }}
docker push ${{ env.REGISTRY }}/namespace-cleaner:${{ github.sha }}