🦊
Dockerfile

GitLab CI Pipeline

Build, test, and deploy with .gitlab-ci.yml — Docker-in-Docker included

📋Configuration Files

.gitlab-ci.yml

yaml
1stages:
2 - build
3 - test
4 - deploy
5
6variables:
7 DOCKER_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
8
9build:
10 stage: build
11 image: docker:24
12 services:
13 - docker:24-dind
14 script:
15 - docker build -t $DOCKER_IMAGE .
16 - docker push $DOCKER_IMAGE
17 only:
18 - main
19
20test:
21 stage: test
22 image: node:20-alpine
23 script:
24 - npm ci
25 - npm test
26
27deploy:
28 stage: deploy
29 image: bitnami/kubectl:latest
30 script:
31 - kubectl set image deployment/myapp app=$DOCKER_IMAGE
32 environment:
33 name: production
34 only:
35 - main

GitLab CI: minimal vs production

What to add before production merge

AspectMinimalProduction
AuthAWS_ACCESS_KEY_ID in CI variablesOIDC / workload identity — no static keys
Runnersshared runners, any tagdedicated runners with pinned tags + isolation
Deploymanual deploy on every commitmain protected; deploy stage manual or tagged release only
Scanbuild onlycontainer_scanning / Trivy gate before push
SecretsKUBECONFIG file variableshort-lived cluster tokens; masked + protected vars
Branch protectionnoneprotected main + merge request pipelines required
📄

Step 01

Use GitLab CI

(01)Add pipeline to repo

Linux
1git add .gitlab-ci.yml
2git commit -m 'Add GitLab CI pipeline'
3git push