Skip to content

Commit 718eb16

Browse files
committed
refactor(ci): update image registry variables and rename sonarqube stage to quality
1 parent b0d12a4 commit 718eb16

2 files changed

Lines changed: 40 additions & 148 deletions

File tree

.gitlab-ci.yml

Lines changed: 32 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ variables:
88
GO_VERSION: "1.25.6"
99

1010
# Image tags
11-
BACKEND_IMAGE: "${CI_REGISTRY_IMAGE}/backend"
12-
TRANSCODER_IMAGE: "${CI_REGISTRY_IMAGE}/transcoder"
11+
BACKEND_IMAGE: "${IMAGE_REGISTRY}/backend"
12+
TRANSCODER_IMAGE: "${IMAGE_REGISTRY}/transcoder"
1313

1414
# Security scanning
1515
TRIVY_VERSION: "0.48.0"
@@ -31,7 +31,7 @@ variables:
3131
stages:
3232
- lint
3333
- test
34-
- sonarqube
34+
- quality
3535
- build
3636
- container-scan
3737
- publish
@@ -127,8 +127,8 @@ test:unit:
127127
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
128128
- if: '$CI_COMMIT_TAG'
129129

130-
sonarqube:check:
131-
stage: sonarqube
130+
quality:sonarqube:
131+
stage: quality
132132
image:
133133
name: sonarsource/sonar-scanner-cli:latest
134134
entrypoint: [""]
@@ -138,8 +138,12 @@ sonarqube:check:
138138
- .sonar/cache
139139
script:
140140
- sonar-scanner
141-
dependencies:
142-
- test:unit
141+
artifacts:
142+
paths:
143+
- .scannerwork/report-task.txt
144+
expire_in: 1 hour
145+
needs:
146+
- test:unit
143147
allow_failure: true
144148
rules:
145149
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
@@ -149,76 +153,36 @@ sonarqube:check:
149153
variables:
150154
- $SONAR_TOKEN
151155

152-
sonarcloud:quality-gate:
153-
stage: sonarqube
154-
image:
155-
name: sonarsource/sonar-scanner-cli:latest
156-
entrypoint: [""]
157-
158-
script:
159-
# - apt install --no-cache curl jq
160-
- |
161-
TASK_URL=$(grep ceTaskUrl .scannerwork/report-task.txt | cut -d'=' -f2-)
162-
echo "CE Task URL: $TASK_URL"
163-
164-
# Poll analysis status
165-
for i in $(seq 1 30); do
166-
RESPONSE=$(curl -s -u "${SONAR_TOKEN}:" "$TASK_URL")
167-
STATUS=$(echo "$RESPONSE" | jq -r '.task.status')
168-
echo "Analysis status: $STATUS"
169-
170-
if [ "$STATUS" = "SUCCESS" ]; then
171-
ANALYSIS_ID=$(echo "$RESPONSE" | jq -r '.task.analysisId')
172-
173-
QG_STATUS=$(curl -s \
174-
-u "${SONAR_TOKEN}:" \
175-
"https://sonarcloud.io/api/qualitygates/project_status?analysisId=${ANALYSIS_ID}" \
176-
| jq -r '.projectStatus.status')
177-
178-
echo "Quality Gate status: $QG_STATUS"
179-
180-
if [ "$QG_STATUS" != "OK" ]; then
181-
echo "❌ Quality Gate FAILED"
182-
exit 1
183-
fi
184-
185-
echo "✅ Quality Gate PASSED"
186-
exit 0
187-
fi
188-
189-
sleep 5
190-
done
191-
192-
echo "❌ Timeout waiting for Quality Gate"
193-
exit 1
194-
195-
needs:
196-
- sonarqube:check
197-
198-
rules:
199-
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
200-
- if: '$CI_COMMIT_TAG'
201-
timeout: 30s
202-
allow_failure: false
203-
204-
# ==================== BUILD STAGE ====================
205-
206156
.build_template: &build_template
207157
stage: build
208-
image: docker:24-dind
209-
services:
210-
- docker:24-dind
158+
# image: docker:24
159+
# services:
160+
# - docker:24-dind
161+
# variables:
162+
# DOCKER_HOST: tcp://docker:2375
163+
# DOCKER_TLS_CERTDIR: ""
211164
before_script:
212-
- echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY
165+
- unset DOCKER_HOST
166+
- unset DOCKER_TLS_CERTDIR
167+
- docker pull public.ecr.aws/aws-cli/aws-cli
168+
- |
169+
docker run --rm \
170+
-e AWS_ACCESS_KEY_ID \
171+
-e AWS_SECRET_ACCESS_KEY \
172+
-e AWS_DEFAULT_REGION \
173+
public.ecr.aws/aws-cli/aws-cli \
174+
ecr get-login-password --region $AWS_DEFAULT_REGION \
175+
| docker login --username AWS --password-stdin ${IMAGE_REGISTRY}
213176
214177
build:backend:
215178
<<: *build_template
216179
script:
217180
- |
218181
# Set image tags
219182
export IMAGE_TAG=${CI_COMMIT_SHORT_SHA}
220-
export IMAGE_VERSIONED=${BACKEND_IMAGE}:${IMAGE_TAG}
183+
export IMAGE_VERSIONED=${IMAGE_REGISTRY}/backend:${IMAGE_TAG}
221184
185+
echo $IMAGE_VERSIONED
222186
# Build image
223187
docker build \
224188
--file docker/backend.dockerfile \
@@ -312,8 +276,8 @@ build:transcoder:
312276
container_scanning:backend:
313277
stage: container-scan
314278
image: docker:24
315-
services:
316-
- docker:24-dind
279+
# services:
280+
# - docker:24-dind
317281
variables:
318282
IMAGE: ${BACKEND_IMAGE}:${CI_COMMIT_SHORT_SHA}
319283
DOCKER_HOST: tcp://docker:2376

taskfile.yaml

Lines changed: 8 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -86,71 +86,6 @@ tasks:
8686
- sops -d -i .env
8787
- sops -d -i example.env
8888

89-
tf:plan:
90-
silent: true
91-
desc: "Generate Terraform/OpenTofu plan for the environment"
92-
dir: terraform/environments
93-
cmds: [tofu plan]
94-
95-
tf:apply:
96-
silent: true
97-
var:
98-
approve: false
99-
dir: terraform/environments
100-
desc: "Apply Terraform/OpenTofu plan to the environment"
101-
cmds:
102-
- tofu apply
103-
104-
tf:apply:auto:
105-
silent: true
106-
dir: terraform/environments
107-
desc: "Apply Terraform/OpenTofu plan (auto approve)"
108-
cmds:
109-
- tofu apply --auto-approve
110-
111-
tf:unlock:
112-
silent: true
113-
dir: terraform/environments
114-
var:
115-
ID:
116-
desc: "Apply Terraform/OpenTofu plan (auto approve)"
117-
cmds:
118-
- tofu force-unlock {{.ID}}
119-
120-
tf:destroy:
121-
silent: true
122-
dir: terraform/environments
123-
desc: "Destroy Terraform/OpenTofu managed infrastructure"
124-
cmds: [tofu destroy]
125-
126-
tf:validate:
127-
silent: true
128-
dir: terraform/environments
129-
desc: "Validate Terraform/OpenTofu configuration"
130-
cmds: [tofu validate]
131-
132-
tf:output:
133-
silent: true
134-
dir: terraform/environments
135-
desc: "Initialize Terraform/OpenTofu with remote backend"
136-
cmds: [tofu output]
137-
138-
tf:init:
139-
silent: true
140-
dir: terraform/environments
141-
desc: "Initialize Terraform/OpenTofu with remote backend"
142-
cmds:
143-
- |
144-
tofu init \
145-
-backend-config="address=https://gitlab.com/api/v4/projects/$GITLAB_PROJECT_ID/terraform/state/$TF_STATE_NAME" \
146-
-backend-config="lock_address=https://gitlab.com/api/v4/projects/$GITLAB_PROJECT_ID/terraform/state/$TF_STATE_NAME/lock" \
147-
-backend-config="unlock_address=https://gitlab.com/api/v4/projects/$GITLAB_PROJECT_ID/terraform/state/$TF_STATE_NAME/lock" \
148-
-backend-config="username=$GITLAB_USERNAME" \
149-
-backend-config="password=$GITLAB_ACCESS_TOKEN" \
150-
-backend-config="lock_method=POST" \
151-
-backend-config="unlock_method=DELETE" \
152-
-backend-config="retry_wait_min=5"
153-
15489
swagger:init:
15590
desc: Generate Swagger documation of Gen Service
15691
cmds:
@@ -162,15 +97,6 @@ tasks:
16297
-g ../main.go \
16398
-o ./backend/swagger
16499
165-
work:sync:
166-
cmds:
167-
- cd libs/core && go mod tidy
168-
- cd libs/idp && go mod tidy
169-
- cd libs/queue && go mod tidy
170-
- cd libs/storage && go mod tidy
171-
- cd backend && go mod tidy
172-
- cd consumer && go mod tidy
173-
174100
sonar:
175101
var:
176102
SONAR_ORG: ${SONAR_ORG}
@@ -195,12 +121,14 @@ tasks:
195121
-Dsonar.links.scm=${CI_REPOSITORY_URL} \
196122
-Dsonar.branch.name=${CI_COMMIT_REF_NAME}
197123
198-
helm:template:
199-
silent: true
200-
dir: k8s
201-
cmds: [helm template playstack ./helm]
202-
203124
gcl:
204125
silent: true
205126
cmds:
206-
- gitlab-ci-local --list | fzf | awk '{print $1}' | xargs gitlab-ci-local
127+
- |
128+
gitlab-ci-local --list | fzf | awk '{print $1}' | xargs gitlab-ci-local \
129+
--variable SONAR_TOKEN=$SONAR_TOKEN \
130+
--variable AWS_DEFAULT_REGION=$AWS_REGION \
131+
--variable AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \
132+
--variable AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \
133+
--variable AWS_ACCOUNT_ID=$AWS_ACCOUNT_ID \
134+
--variable IMAGE_REGISTRY=$IMAGE_REGISTRY

0 commit comments

Comments
 (0)