-
Notifications
You must be signed in to change notification settings - Fork 1
/
.gitlab-ci.yml
172 lines (159 loc) · 4.16 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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
include:
- project: 'renovate-bot/renovate-runner'
file: '/templates/renovate.gitlab-ci.yml'
stages:
- lint
- plan
- deploy
- renovate
image: henrywhitaker3/pipeline
##############
# Kubernetes #
##############
diffs:
stage: plan
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
script:
- ./scripts/pipeline_changes.sh
###########
# Ansible #
###########
.playbooks:
variables:
ANSIBLE_CONFIG: ./ansible.cfg
parallel:
matrix:
- PLAYBOOK:
- vpn
- k3s
- haproxy
- speakers
- adguard
- minio
- proxmox
rules:
- if: $SKIP_ANSIBLE == "true"
when: never
- if: $CI_COMMIT_BRANCH == "main" && $ANSIBLE_RUN_ALL == "true"
- if: $CI_COMMIT_BRANCH == "main" && $SKIP_ANSIBLE != "true"
changes:
- ansible/playbooks/$PLAYBOOK/*
- ansible/playbooks/$PLAYBOOK/**/*
- ansible/inventory/*
- ansible/inventory/**/*
- ansible/roles/**/*
- ansible/inventory
- .gitlab-ci.yml
- .ansible-lint
ansible lint:
stage: lint
extends: .playbooks
script:
- task ci:age:key AGE_KEY="$AGE_KEY"
- task ci:lint PLAYBOOK=ansible/playbooks/$PLAYBOOK/main.yaml
ansible play:
stage: deploy
extends: .playbooks
script:
- eval $(ssh-agent -s)
- task ci:playbook PLAYBOOK=ansible/playbooks/$PLAYBOOK/main.yaml AGE_KEY="$AGE_KEY" SSH_KEY="$SSH_KEY"
environment:
name: "$PLAYBOOK"
#############
# Terraform #
#############
.terraform:base:
image: henrywhitaker3/pipeline
before_script:
- cd terraform/$TF_DIR
- |
terraform init \
-backend-config="address=https://gitlab.com/api/v4/projects/45412263/terraform/state/$TF_STATE" \
-backend-config="lock_address=https://gitlab.com/api/v4/projects/45412263/terraform/state/$TF_STATE/lock" \
-backend-config="unlock_address=https://gitlab.com/api/v4/projects/45412263/terraform/state/$TF_STATE/lock" \
-backend-config="username=henrywhitaker3" \
-backend-config="password=$TERRAFORM_ACCESS_TOKEN" \
-backend-config="lock_method=POST" \
-backend-config="unlock_method=DELETE" \
-backend-config="retry_wait_min=5"
rules:
- if: $SKIP_TERRAFORM == "true"
when: never
- if: $CI_COMMIT_BRANCH == "main" && $SKIP_TERRAFORM != "true"
changes:
- terraform/$TF_DIR/*
- .gitlab-ci.yml
parallel:
matrix:
- TF_STATE: tf-state
TF_DIR: infra
- TF_STATE: post
TF_DIR: post
TF_VAR_infra_state_url: https://gitlab.com/api/v4/projects/45412263/terraform/state/tf-state
TF_VAR_infra_state_token: $TERRAFORM_ACCESS_TOKEN
tf validate:
stage: lint
extends:
- .terraform:base
script:
- terraform validate
rules:
- !reference [.terraform:base, rules]
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
changes:
- terraform/*
tf plan:
stage: plan
extends:
- .terraform:base
script:
- terraform plan -out planfile
artifacts:
paths:
- terraform/$TF_DIR/planfile
rules:
- !reference [.terraform:base, rules]
tf deploy:
stage: deploy
extends:
- .terraform:base
script:
- terraform apply -auto-approve planfile
dependencies:
- tf plan
environment:
name: $TF_DIR
# when: manual
##########
# Docker #
##########
build docker image:
stage: deploy
image:
name: gcr.io/kaniko-project/executor:v1.23.2-debug
entrypoint: [""]
script:
- echo $DOCKER_TOKEN | base64 -d > /kaniko/.docker/config.json
- /kaniko/executor
--context "${CI_PROJECT_DIR}"
--dockerfile "${CI_PROJECT_DIR}/Dockerfile"
--destination "henrywhitaker3/pipeline:latest"
rules:
- if: ($BUILD_DOCKER_IMAGES == "true") && $CI_COMMIT_BRANCH == "main"
- if: $SKIP_DOCKER_IMAGES == "true"
when: never
- if: $CI_COMMIT_BRANCH == "main"
changes:
- Dockerfile
############
# Renovate #
############
renovate:
stage: renovate
image: ghcr.io/renovatebot/renovate:39
variables:
RENOVATE_EXTRA_FLAGS: henrywhitaker3/homelab
rules:
- if: '$CI_PIPELINE_SOURCE == "schedule"'
- if: '$CI_PIPELINE_SOURCE == "push"'