Skip to content

Commit eabef60

Browse files
authored
Merge pull request #94 from fly-apps/timescaledb-support
Timescaledb support
2 parents 829882f + 9be1e8d commit eabef60

File tree

3 files changed

+81
-15
lines changed

3 files changed

+81
-15
lines changed

.github/workflows/ci.yaml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,38 +32,38 @@ jobs:
3232
id: get-latest-tag
3333
uses: "WyriHaximus/github-action-get-previous-tag@v1"
3434
-
35-
name: Build and push Postgres 14
36-
id: docker_build_14
35+
name: Build and push Postgres 15
36+
id: docker_build_15
3737
uses: docker/build-push-action@v3
3838
with:
3939
build-args: |
40-
PG_VERSION=14.6
41-
PG_MAJOR_VERSION=14
40+
PG_VERSION=15.1
41+
PG_MAJOR_VERSION=15
4242
VERSION=${{ steps.get-latest-tag.outputs.tag }}
4343
context: .
4444
file: ./Dockerfile
4545
push: true
4646
tags: |
47-
flyio/postgres-flex:14
48-
flyio/postgres-flex:14.6
47+
flyio/postgres-flex:15
48+
flyio/postgres-flex:15.1
4949
-
50-
name: Build and push Postgres 15
51-
id: docker_build_15
50+
name: Build and push Postgres 15 Timescale DB
51+
id: docker_build_15_timescaledb
5252
uses: docker/build-push-action@v3
5353
with:
5454
build-args: |
5555
PG_VERSION=15.1
5656
PG_MAJOR_VERSION=15
5757
VERSION=${{ steps.get-latest-tag.outputs.tag }}
5858
context: .
59-
file: ./Dockerfile
59+
file: ./Dockerfile-timescaledb
6060
push: true
6161
tags: |
62-
flyio/postgres-flex:15
63-
flyio/postgres-flex:15.1
64-
-
65-
name: Postgres 14 Image digest
66-
run: echo ${{ steps.docker_build_14.outputs.digest }}
62+
flyio/postgres-flex-timescaledb:15
63+
flyio/postgres-flex-timescaledb:15.1
6764
-
6865
name: Postgres 15 Image digest
6966
run: echo ${{ steps.docker_build_15.outputs.digest }}
67+
-
68+
name: Postgres 15 TimescaleDB Image digest
69+
run: echo ${{ steps.docker_build_15_timescaledb.outputs.digest }}

Dockerfile-timescaledb

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
ARG PG_VERSION=15.1
2+
ARG PG_MAJOR_VERSION=15
3+
ARG VERSION=custom
4+
5+
FROM golang:1.19 as flyutil
6+
7+
WORKDIR /go/src/github.com/fly-examples/fly-postgres
8+
COPY . .
9+
10+
RUN CGO_ENABLED=0 GOOS=linux go build -v -o /fly/bin/event_handler ./cmd/event_handler
11+
RUN CGO_ENABLED=0 GOOS=linux go build -v -o /fly/bin/failover_validation ./cmd/failover_validation
12+
RUN CGO_ENABLED=0 GOOS=linux go build -v -o /fly/bin/pg_unregister ./cmd/pg_unregister
13+
RUN CGO_ENABLED=0 GOOS=linux go build -v -o /fly/bin/start_monitor ./cmd/monitor
14+
RUN CGO_ENABLED=0 GOOS=linux go build -v -o /fly/bin/start_admin_server ./cmd/admin_server
15+
RUN CGO_ENABLED=0 GOOS=linux go build -v -o /fly/bin/start ./cmd/start
16+
17+
COPY ./bin/* /fly/bin/
18+
19+
FROM wrouesnel/postgres_exporter:latest AS postgres_exporter
20+
21+
FROM postgres:${PG_VERSION}
22+
ENV PGDATA=/data/postgresql
23+
ARG VERSION
24+
ARG PG_MAJOR_VERSION
25+
ARG POSTGIS_MAJOR=3
26+
27+
28+
LABEL fly.app_role=postgres_cluster
29+
LABEL fly.version=${VERSION}
30+
LABEL fly.pg-version=${PG_VERSION}
31+
LABEL fly.pg-manager=repmgr
32+
33+
RUN apt-get update && apt-get install --no-install-recommends -y \
34+
ca-certificates iproute2 postgresql-$PG_MAJOR_VERSION-repmgr curl bash dnsutils vim procps jq pgbouncer ssh \
35+
&& apt autoremove -y
36+
37+
RUN echo "deb https://packagecloud.io/timescale/timescaledb/debian/ $(cat /etc/os-release | grep VERSION_CODENAME | cut -d'=' -f2) main" > /etc/apt/sources.list.d/timescaledb.list \
38+
&& curl -L https://packagecloud.io/timescale/timescaledb/gpgkey | apt-key add -
39+
40+
RUN apt-get update && apt-get install --no-install-recommends -y \
41+
postgresql-$PG_MAJOR_VERSION-postgis-$POSTGIS_MAJOR \
42+
postgresql-$PG_MAJOR_VERSION-postgis-$POSTGIS_MAJOR-scripts \
43+
timescaledb-2-postgresql-$PG_MAJOR_VERSION \
44+
timescaledb-toolkit-postgresql-$PG_MAJOR_VERSION \
45+
&& apt autoremove -y
46+
47+
COPY --from=0 /fly/bin/* /usr/local/bin
48+
COPY --from=postgres_exporter /postgres_exporter /usr/local/bin/
49+
50+
ADD /config/* /fly/
51+
52+
RUN mkdir -p /run/haproxy/
53+
RUN usermod -d /data postgres
54+
55+
ENV TIMESCALEDB_ENABLED=true
56+
57+
EXPOSE 5432
58+
59+
60+
CMD ["start"]

internal/flypg/pg.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,12 @@ func (c *PGConfig) SetDefaults() error {
220220
}
221221
sharedBuffersMb := sharedBuffersBytes / (1024 * 1024)
222222

223+
sharedPreloadLibraries := []string{"repmgr"}
224+
// preload timescaledb if enabled
225+
if os.Getenv("TIMESCALEDB_ENABLED") == "true" {
226+
sharedPreloadLibraries = append(sharedPreloadLibraries, "timescaledb")
227+
}
228+
223229
conf := ConfigMap{
224230
"random_page_cost": "1.1",
225231
"port": c.port,
@@ -234,7 +240,7 @@ func (c *PGConfig) SetDefaults() error {
234240
"hot_standby": true,
235241
"archive_mode": true,
236242
"archive_command": "'/bin/true'",
237-
"shared_preload_libraries": "repmgr",
243+
"shared_preload_libraries": fmt.Sprintf("'%s'", strings.Join(sharedPreloadLibraries, ",")),
238244
}
239245

240246
c.internalConfig = conf

0 commit comments

Comments
 (0)