Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration deploy hook #65

Merged
merged 10 commits into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.0
nathannascimentozup marked this conversation as resolved.
Show resolved Hide resolved
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/Dockerfile";;
"horusec-analytic")
IMAGE_NAME="horuszup/horusec-analytic"
DIRECTORY="./horusec-analytic";;
DIRECTORY="./horusec-analytic/deployments/Dockerfile";;
"horusec-api")
IMAGE_NAME="horuszup/horusec-api"
DIRECTORY="./horusec-api";;
DIRECTORY="./horusec-api/deployments/Dockerfile";;
"horusec-manager")
IMAGE_NAME="horuszup/horusec-manager"
DIRECTORY="./horusec-manager";;
DIRECTORY="./horusec-manager/deployments/Dockerfile";;
"horusec-messages")
IMAGE_NAME="horuszup/horusec-messages"
DIRECTORY="./horusec-messages";;
DIRECTORY="./horusec-messages/deployments/Dockerfile";;
"horusec-migration")
IMAGE_NAME="horuszup/horusec-migration"
DIRECTORY="./deployments/dockerfiles/migration/Dockerfile";;
*)
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 .
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 .
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 }}