forked from ishwar6/django_ci_cd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
49 lines (40 loc) · 1.46 KB
/
.gitlab-ci.yml
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
#gitlab ci uses docker images to run the pipeline and these images we have to define here.
image: docker:19.03.5
services:
- docker:19.03.5-dind
stages:
- Build
- Push
before_script:
- apk add python3 #install it in our docker image
- pip3 install awscli==1.18.8
- docker load --input data/image.tar #load the image from artifact from previous job
- $(aws ecr get-login --no-include-email --region us-east-1) #login command
Build:
stage: Build
before_script: []
script:
- mkdir data/
- docker build --compress -t proxy . # build our docker file in compress state in same path and tag it with "proxy"
- docker save --output data/image.tar proxy
artifacts: # to pass file from one job to another
name: image
paths:
- data/
Push Dev:
stage: Push
script:
- docker tag proxy:latest $ECR_REPO:dev
- docker push $ECR_REPO:dev #to push repo to AWS ECR
rules:
- if: "$CI_COMMIT_BRANCH=='main' " # to specify when to run the job, when our branch in main.
Push Release:
stage: Push
script:
- export TAGGED_ECR_REPO=$ECR_REPO:$(echo $CI_COMMIT_TAG | sed 's/-release//') #to strip of the release no and append it to ECR_REPO
- docker tag proxy:latest $TAGGED_ECR_REPO
- docker push $TAGGED_ECR_REPO
- docker tag $TAGGED_ECR_REPO $ECR_REPO:latest
- docker push $ECR_REPO:latest
rulse:
- if: "$CI_COMMIT_BRANCH =~ /^*-release$/" #this will be triggered when anything ending with release comes.