Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
55 changes: 41 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# Copyright 2019 AppsCode Inc.
# Copyright 2016 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

SHELL=/bin/bash -o pipefail

# The binary to build (just the basename).
Expand Down Expand Up @@ -44,8 +59,8 @@ BIN_PLATFORMS := $(DOCKER_PLATFORMS)
OS := $(if $(GOOS),$(GOOS),$(shell go env GOOS))
ARCH := $(if $(GOARCH),$(GOARCH),$(shell go env GOARCH))

BASEIMAGE_PROD ?= postgres:9.5-alpine
BASEIMAGE_DBG ?= postgres:9.5
BASEIMAGE_PROD ?= postgres:11.2-alpine
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first code should be for 9.x version. Let's talk on Monday. @hossainemruz

BASEIMAGE_DBG ?= postgres:11.2

IMAGE := $(REGISTRY)/$(BIN)
VERSION_PROD := $(VERSION)
Expand All @@ -54,7 +69,7 @@ TAG := $(VERSION)_$(OS)_$(ARCH)
TAG_PROD := $(TAG)
TAG_DBG := $(VERSION)-dbg_$(OS)_$(ARCH)

GO_VERSION ?= 1.12.5
GO_VERSION ?= 1.12.7
BUILD_IMAGE ?= appscode/golang-dev:$(GO_VERSION)-stretch

OUTBIN = bin/$(OS)_$(ARCH)/$(BIN)
Expand Down Expand Up @@ -164,9 +179,21 @@ $(OUTBIN): .go/$(OUTBIN).stamp
commit_timestamp=$(commit_timestamp) \
./hack/build.sh \
"
@if [ $(COMPRESS) = yes ] && [ $(OS) != windows ]; then \
echo "compressing $(OUTBIN)"; \
upx --brute .go/$(OUTBIN); \
@if [ $(COMPRESS) = yes ] && [ $(OS) != darwin ]; then \
echo "compressing $(OUTBIN)"; \
docker run \
-i \
--rm \
-u $$(id -u):$$(id -g) \
-v $$(pwd):/src \
-w /src \
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin \
-v $$(pwd)/.go/bin/$(OS)_$(ARCH):/go/bin/$(OS)_$(ARCH) \
-v $$(pwd)/.go/cache:/.cache \
--env HTTP_PROXY=$(HTTP_PROXY) \
--env HTTPS_PROXY=$(HTTPS_PROXY) \
$(BUILD_IMAGE) \
upx --brute /go/$(OUTBIN); \
fi
@if ! cmp -s .go/$(OUTBIN) $(OUTBIN); then \
mv .go/$(OUTBIN) $(OUTBIN); \
Expand Down Expand Up @@ -255,28 +282,28 @@ dev: gen fmt push
ci: lint test build #cover

.PHONY: qa
qa: docker-manifest
qa:
@if [ "$$APPSCODE_ENV" = "prod" ]; then \
echo "Nothing to do in prod env. Are you trying to 'release' binaries to prod?"; \
exit 1; \
fi
@if [ "$(version_strategy)" = "git_tag" ]; then \
@if [ "$(version_strategy)" = "tag" ]; then \
echo "Are you trying to 'release' binaries to prod?"; \
exit 1; \
fi
@$(MAKE) clean all-push --no-print-directory
@$(MAKE) clean all-push docker-manifest --no-print-directory

.PHONY: release
release: docker-manifest
release:
@if [ "$$APPSCODE_ENV" != "prod" ]; then \
echo "'release' only works in PROD env."; \
exit 1; \
fi
@if [ "$(version_strategy)" != "git_tag" ]; then \
echo "'apply_tag' to release binaries and/or docker images."; \
exit 1; \
@if [ "$(version_strategy)" != "tag" ]; then \
echo "apply tag to release binaries and/or docker images."; \
exit 1; \
fi
@$(MAKE) clean all-push --no-print-directory
@$(MAKE) clean all-push docker-manifest --no-print-directory

.PHONY: clean
clean:
Expand Down
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,31 @@
[![Twitter](https://img.shields.io/twitter/follow/appscodehq.svg?style=social&logo=twitter&label=Follow)](https://twitter.com/intent/follow?screen_name=AppsCodeHQ)

# Postgres

Postgres backup and restore plugin for [Stash by AppsCode](https://appscode.com/products/stash).

---
## Install

Install PostgreSQL 11.2 backup or restore plugin for Stash as below.

```console
helm repo add appscode https://charts.appscode.com/stable/
helm repo update
helm install appscode/postgres-stash --name=postgres-stash-11.2 --version=11.2
```

**Stash binaries collects anonymous usage statistics to help us learn how the software is being used and how we can improve it. To disable stats collection, run the operator with the flag** `--enable-analytics=false`.
To install catalog for all supported PostgreSQL versions, please visit [here](https://github.com/stashed/catalog).

---
## Uninstall

Uninstall PostgreSQL 11.2 backup or restore plugin for Stash as below.

```console
helm delete postgres-stash-11.2
```

## Support

We use Slack for public discussions. To chit chat with us or the rest of the community, join us in the [AppsCode Slack team](https://appscode.slack.com/messages/C8NCX6N23/details/) channel `#stash`. To sign up, use our [Slack inviter](https://slack.appscode.com/).

If you have found a bug with Stash or want to request for new features, please [file an issue](https://github.com/stashed/stash/issues/new).
22 changes: 22 additions & 0 deletions chart/postgres-stash/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
12 changes: 12 additions & 0 deletions chart/postgres-stash/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
description: 'postgres-stash by AppsCode - PostgreSQL database backup and restore plugin for Stash.'
name: postgres-stash
version: 11.2
appVersion: 11.2
home: https://github.com/stashed/postgres
icon: https://cdn.appscode.com/images/icon/stash.png
sources:
- https://github.com/stashed/postgres
maintainers:
- name: appscode
email: support@appscode.com
79 changes: 79 additions & 0 deletions chart/postgres-stash/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Postgres-stash

[postgres-stash](https://github.com/stashed/postgres-stash) - PostgreSQL database backup/restore plugin for [Stash](https://appscode.com/products/stash/) by AppsCode.

## TL;DR;

```console
helm repo add appscode https://charts.appscode.com/stable/
helm repo update
helm install appscode/postgres-stash --name=postgres-stash-11.2 --version=11.2
```

## Introduction

This chart installs necessary `Function` and `Task` definition to backup or restore PostgreSQL database 11.2 using Stash.

## Prerequisites

- Kubernetes 1.11+

## Installing the Chart

- Add AppsCode chart repository to your helm repository list,

```console
helm repo add appscode https://charts.appscode.com/stable/
```

- Update helm repositories to fetch latest charts from the remove repository,

```console
helm repo update
```

- Install the chart with the release name `postgres-stash-11.2` run the following command,

```console
helm install appscode/postgres-stash --name=postgres-stash-11.2 --version=11.2
```

The above commands installs `Functions` and `Task` crds that are necessary to backup PostgreSQL database 11.2 using Stash.

## Uninstalling the Chart

To uninstall/delete the `postgres-stash-11.2` run the following command,

```console
helm delete postgres-stash-11.2
```

The command removes all the Kubernetes components associated with the chart and deletes the release.

## Configuration

The following table lists the configurable parameters of the `postgre-stash` chart and their default values.

| Parameter | Description | Default |
| ----------------- | -------------------------------------------------------------------------------------------------------------------------------- | ---------------- |
| `docker.registry` | Docker registry used to pull respective images | `appscode` |
| `docker.image` | Docker image used to backup/restore PosegreSQL database | `postgres-stash` |
| `docker.tag` | Tag of the image that is used to backup/restore PostgreSQL database. This is usually same as the database version it can backup. | `11.2` |
| `backup.pgArgs` | Optional arguments to pass to `pgdump` command for bakcup | |
| `restore.pgArgs` | Optional arguments to pass to `psql` command for restoration | |
| `metrics.enabled` | Specifies whether to send Prometheus metrics | `true` |
| `metrics.labels` | Optional comma separated labels to add to the Prometheus metrics | |

Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`.

For example:

```console
helm install --name postgres-stash-11.2 --set metrics.enabled=false appscode/postgres-stash
```

**Tips:** Use escape character (`\`) while providing multiple comma-separated labels for `metrics.labels`.

```console
helm install chart/postgres-stash --set metrics.labels="k1=v1\,k2=v2"
```
7 changes: 7 additions & 0 deletions chart/postgres-stash/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
To verify that all Functions are installed successfully, run:

kubectl get function.stash.appscode.com

To verify that all Tasks are installed successfully, run:

kubectl get task.stash.appscode.com
40 changes: 40 additions & 0 deletions chart/postgres-stash/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "postgres-stash.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "postgres-stash.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "postgres-stash.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

# default labels for posgres-stash resources
{{- define "postgres-stash.labels" -}}
app.kubernetes.io/name: {{ include "postgres-stash.name" . }}
helm.sh/chart: {{ include "postgres-stash.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}
45 changes: 45 additions & 0 deletions chart/postgres-stash/templates/pg-backup-function.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
apiVersion: stash.appscode.com/v1beta1
kind: Function
metadata:
name: pg-backup-{{- .Chart.Version }}
labels:
{{- include "postgres-stash.labels" . | nindent 4 }}
spec:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we handle resources?

image: {{ .Values.docker.registry }}/{{ .Values.docker.image }}:{{- .Values.docker.tag }}
args:
- backup-pg
# setup information
- --provider=${REPOSITORY_PROVIDER:=}
- --bucket=${REPOSITORY_BUCKET:=}
- --endpoint=${REPOSITORY_ENDPOINT:=}
- --rest-server-url=${REPOSITORY_URL:=}
- --path=${REPOSITORY_PREFIX:=}
- --secret-dir=/etc/repository/secret
- --scratch-dir=/tmp
- --enable-cache=${ENABLE_CACHE:=true}
- --max-connections=${MAX_CONNECTIONS:=0} # 0 indicates use default connection limit
- --hostname=${HOSTNAME:=}
- --pg-args=${pgArgs:={{ .Values.backup.pgArgs }}} # optional arguments pass to pgdump command
# target information
- --namespace=${NAMESPACE:=default}
- --app-binding=${TARGET_NAME:=}
# cleanup information
- --retention-keep-last=${RETENTION_KEEP_LAST:=0}
- --retention-keep-hourly=${RETENTION_KEEP_HOURLY:=0}
- --retention-keep-daily=${RETENTION_KEEP_DAILY:=0}
- --retention-keep-weekly=${RETENTION_KEEP_WEEKLY:=0}
- --retention-keep-monthly=${RETENTION_KEEP_MONTHLY:=0}
- --retention-keep-yearly=${RETENTION_KEEP_YEARLY:=0}
- --retention-keep-tags=${RETENTION_KEEP_TAGS:=}
- --retention-prune=${RETENTION_PRUNE:=false}
- --retention-dry-run=${RETENTION_DRY_RUN:=false}
# output & metric information
- --output-dir=${outputDir:=}
- --metrics-enabled={{ .Values.metrics.enabled }}
- --metrics-pushgateway-url=${PROMETHEUS_PUSHGATEWAY_URL:=}
{{- if .Values.metrics.labels }}
- --metrics-labels={{ .Values.metrics.labels | quote }}
{{- end }}
volumeMounts:
- name: ${secretVolume}
mountPath: /etc/repository/secret
22 changes: 22 additions & 0 deletions chart/postgres-stash/templates/pg-backup-task.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: stash.appscode.com/v1beta1
kind: Task
metadata:
name: pg-backup-{{- .Chart.Version }}
labels:
{{- include "postgres-stash.labels" . | nindent 4 }}
spec:
steps:
- name: pg-backup-{{- .Chart.Version }}
params:
- name: outputDir
value: /tmp/output
- name: secretVolume
value: secret-volume
- name: update-status
params:
- name: outputDir
value: /tmp/output
volumes:
- name: secret-volume
secret:
secretName: ${REPOSITORY_SECRET_NAME}
Loading