diff --git a/deployments/dockerfiles/migration/.semver.yaml b/deployments/dockerfiles/migration/.semver.yaml new file mode 100644 index 000000000..380baee26 --- /dev/null +++ b/deployments/dockerfiles/migration/.semver.yaml @@ -0,0 +1,4 @@ +alpha: 0 +beta: 0 +rc: 0 +release: v0.0.1 diff --git a/deployments/dockerfiles/migration/Dockerfile b/deployments/dockerfiles/migration/Dockerfile new file mode 100644 index 000000000..7d5e72b4d --- /dev/null +++ b/deployments/dockerfiles/migration/Dockerfile @@ -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" ] \ No newline at end of file diff --git a/deployments/dockerfiles/migration/migrate.sh b/deployments/dockerfiles/migration/migrate.sh new file mode 100644 index 000000000..e7d35a9bc --- /dev/null +++ b/deployments/dockerfiles/migration/migrate.sh @@ -0,0 +1,2 @@ +#!/bin/sh +migrate -path "/horusec-migrations" -database "$HORUSEC_DATABASE_SQL_URI" up "$@" diff --git a/deployments/scripts/update-image-service.sh b/deployments/scripts/update-image-service.sh index 3ba3fb459..087ca3863 100755 --- a/deployments/scripts/update-image-service.sh +++ b/deployments/scripts/update-image-service.sh @@ -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" @@ -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 diff --git a/horusec-account/deployments/helm/horusec-account/templates/databasemigration.yaml b/horusec-account/deployments/helm/horusec-account/templates/databasemigration.yaml new file mode 100644 index 000000000..62e45118e --- /dev/null +++ b/horusec-account/deployments/helm/horusec-account/templates/databasemigration.yaml @@ -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 }} diff --git a/horusec-analytic/deployments/helm/horusec-analytic/templates/databasemigration.yaml b/horusec-analytic/deployments/helm/horusec-analytic/templates/databasemigration.yaml new file mode 100644 index 000000000..1d6151924 --- /dev/null +++ b/horusec-analytic/deployments/helm/horusec-analytic/templates/databasemigration.yaml @@ -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 }} diff --git a/horusec-api/deployments/helm/horusec-api/templates/databasemigration.yaml b/horusec-api/deployments/helm/horusec-api/templates/databasemigration.yaml new file mode 100644 index 000000000..1d6151924 --- /dev/null +++ b/horusec-api/deployments/helm/horusec-api/templates/databasemigration.yaml @@ -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 }}