Skip to content

Commit

Permalink
Migration deploy hook (#65)
Browse files Browse the repository at this point in the history
* Adding migration dockerfile

* Improving migration dockerfile

* Using env in migration

* Adding migration template

* Fixing migration template

* Adding migration image script

* Updating helm hook

* Fixing mingration version

* Fixing  service image script builder

Co-authored-by: Horusec <horusec@zup.com.br>
  • Loading branch information
nathannascimentozup and horusec authored Oct 21, 2020
1 parent 0d61c17 commit c4a75e1
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 7 deletions.
4 changes: 4 additions & 0 deletions deployments/dockerfiles/migration/.semver.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
alpha: 0
beta: 0
rc: 0
release: v0.0.1
8 changes: 8 additions & 0 deletions deployments/dockerfiles/migration/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM migrate/migrate:v4.13.0

ADD development-kit/pkg/databases/relational/migration /horusec-migrations
ADD deployments/dockerfiles/migration/migrate.sh /usr/local/bin

RUN chmod +x /usr/local/bin/migrate.sh

ENTRYPOINT [ "migrate.sh" ]
2 changes: 2 additions & 0 deletions deployments/dockerfiles/migration/migrate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
migrate -path "/horusec-migrations" -database "$HORUSEC_DATABASE_SQL_URI" up "$@"
17 changes: 10 additions & 7 deletions deployments/scripts/update-image-service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,22 @@ getDirectoryAndImageNameByToolName () {
case "$SERVICE_NAME" in
"horusec-account")
IMAGE_NAME="horuszup/horusec-account"
DIRECTORY="./horusec-account";;
DIRECTORY="./horusec-account/deployments";;
"horusec-analytic")
IMAGE_NAME="horuszup/horusec-analytic"
DIRECTORY="./horusec-analytic";;
DIRECTORY="./horusec-analytic/deployments";;
"horusec-api")
IMAGE_NAME="horuszup/horusec-api"
DIRECTORY="./horusec-api";;
DIRECTORY="./horusec-api/deployments";;
"horusec-manager")
IMAGE_NAME="horuszup/horusec-manager"
DIRECTORY="./horusec-manager";;
DIRECTORY="./horusec-manager/deployments";;
"horusec-messages")
IMAGE_NAME="horuszup/horusec-messages"
DIRECTORY="./horusec-messages";;
DIRECTORY="./horusec-messages/deployments";;
"horusec-migration")
IMAGE_NAME="horuszup/horusec-migration"
DIRECTORY="./deployments/dockerfiles/migration";;
*)
echo "Param Service Name is invalid, please use the examples bellow allowed and try again!"
echo "Params Service Name allowed: horusec-account, horusec-analytic, horusec-api, horusec-manager, horusec-messages"
Expand Down Expand Up @@ -116,11 +119,11 @@ updateVersion () {

if [ "$IS_TO_UPDATE_LATEST" == "true" ]
then
docker build -t "$IMAGE_NAME:latest" -f $DIRECTORY/deployments/Dockerfile .
docker build -t "$IMAGE_NAME:latest" -f $DIRECTORY/Dockerfile .
docker push "$IMAGE_NAME:latest"
fi

docker build -t "$IMAGE_NAME:$LATEST_VERSION" -f $DIRECTORY/deployments/Dockerfile .
docker build -t "$IMAGE_NAME:$LATEST_VERSION" -f $DIRECTORY/Dockerfile .
docker push "$IMAGE_NAME:$LATEST_VERSION"

rollback_version_packagejson
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
apiVersion: batch/v1
kind: Job
metadata:
name: "{{ .Release.Name }}"
labels:
app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
app.kubernetes.io/instance: {{ .Release.Name | quote }}
app.kubernetes.io/version: {{ .Chart.AppVersion }}
helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
annotations:
"helm.sh/hook": pre-install,pre-upgrade
"helm.sh/hook-weight": "-5"
"helm.sh/hook-delete-policy": hook-succeeded,hook-failed
spec:
template:
metadata:
name: "{{ .Release.Name }}"
labels:
app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
app.kubernetes.io/instance: {{ .Release.Name | quote }}
helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
spec:
restartPolicy: Never
containers:
- name: horusec-database-migration
image: "horuszup/horusec-migration"
command: ["migrate.sh"]
env:
{{- range .Values.env }}
- name: {{ .name }}
value: "{{ .value }}"
{{- end }}
{{- range .Values.envFromSecret }}
- name: {{ .name }}
valueFrom:
secretKeyRef:
name: {{ .key }}
key: {{ .key }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
apiVersion: batch/v1
kind: Job
metadata:
name: "{{ .Release.Name }}"
labels:
app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
app.kubernetes.io/instance: {{ .Release.Name | quote }}
app.kubernetes.io/version: {{ .Chart.AppVersion }}
helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
annotations:
"helm.sh/hook": pre-install,pre-upgrade
"helm.sh/hook-weight": "-5"
"helm.sh/hook-delete-policy": hook-succeeded
spec:
template:
metadata:
name: "{{ .Release.Name }}"
labels:
app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
app.kubernetes.io/instance: {{ .Release.Name | quote }}
helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
spec:
restartPolicy: Never
containers:
- name: horusec-database-migration
image: "horuszup/horusec-migration"
command: ["migrate.sh"]
env:
{{- range .Values.env }}
- name: {{ .name }}
value: "{{ .value }}"
{{- end }}
{{- range .Values.envFromSecret }}
- name: {{ .name }}
valueFrom:
secretKeyRef:
name: {{ .key }}
key: {{ .key }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
apiVersion: batch/v1
kind: Job
metadata:
name: "{{ .Release.Name }}"
labels:
app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
app.kubernetes.io/instance: {{ .Release.Name | quote }}
app.kubernetes.io/version: {{ .Chart.AppVersion }}
helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
annotations:
"helm.sh/hook": pre-install,pre-upgrade
"helm.sh/hook-weight": "-5"
"helm.sh/hook-delete-policy": hook-succeeded
spec:
template:
metadata:
name: "{{ .Release.Name }}"
labels:
app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
app.kubernetes.io/instance: {{ .Release.Name | quote }}
helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
spec:
restartPolicy: Never
containers:
- name: horusec-database-migration
image: "horuszup/horusec-migration"
command: ["migrate.sh"]
env:
{{- range .Values.env }}
- name: {{ .name }}
value: "{{ .value }}"
{{- end }}
{{- range .Values.envFromSecret }}
- name: {{ .name }}
valueFrom:
secretKeyRef:
name: {{ .key }}
key: {{ .key }}
{{- end }}

0 comments on commit c4a75e1

Please sign in to comment.