Add GitLab CI/CD pipeline for automated Docker build and Kubernetes deployment
This commit is contained in:
parent
9e20cbc33f
commit
ed0e98fb4f
2 changed files with 47 additions and 4 deletions
38
.gitlab-ci.yml
Normal file
38
.gitlab-ci.yml
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
include:
|
||||
- template: Jobs/Build.gitlab-ci.yml
|
||||
- template: Jobs/Deploy.gitlab-ci.yml
|
||||
|
||||
variables:
|
||||
DOCKER_BUILDKIT: 1
|
||||
CI_BUILDX_ARCHS: "linux/amd64"
|
||||
|
||||
build:
|
||||
stage: build
|
||||
image: docker:24
|
||||
services:
|
||||
- docker:24-dind
|
||||
before_script:
|
||||
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
|
||||
script:
|
||||
- docker build -f k8s/Dockerfile -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA -t $CI_REGISTRY_IMAGE:latest .
|
||||
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
|
||||
- docker push $CI_REGISTRY_IMAGE:latest
|
||||
rules:
|
||||
- if: $CI_COMMIT_BRANCH == "main"
|
||||
|
||||
deploy:
|
||||
stage: deploy
|
||||
image:
|
||||
name: bitnami/kubectl:latest
|
||||
entrypoint: ['']
|
||||
script:
|
||||
- kubectl config get-contexts
|
||||
- kubectl config use-context graham/towerops:towerops
|
||||
- kubectl set image deployment/towerops towerops=$CI_REGISTRY_IMAGE:$CI_COMMIT_SHA -n towerops
|
||||
- kubectl rollout status deployment/towerops -n towerops --timeout=5m
|
||||
environment:
|
||||
name: production
|
||||
kubernetes:
|
||||
namespace: towerops
|
||||
rules:
|
||||
- if: $CI_COMMIT_BRANCH == "main"
|
||||
|
|
@ -1,5 +1,10 @@
|
|||
ci_access:
|
||||
projects:
|
||||
- id: graham/towerops
|
||||
default_namespace: towerops
|
||||
|
||||
user_access:
|
||||
access_as:
|
||||
agent: {}
|
||||
projects:
|
||||
- id: graham/towerops
|
||||
access_as:
|
||||
agent: {}
|
||||
projects:
|
||||
- id: graham/towerops
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue