diff --git a/docker-compose.yml b/docker-compose.yml index 55aefe0669..d173eca22f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -540,9 +540,14 @@ services: # ****************** # Postgres used by Feature Flag service ffs_postgres: - image: postgres:16.1 + image: ${IMAGE_NAME}:${IMAGE_VERSION}-ffs_postgres container_name: postgres user: postgres + build: + context: ./ + dockerfile: ./src/ffs_postgres/Dockerfile + cache_from: + - ${IMAGE_NAME}:${IMAGE_VERSION}-ffs_postgres deploy: resources: limits: diff --git a/src/featureflagservice/priv/repo/migrations/20220524172636_create_featureflags.exs b/src/featureflagservice/priv/repo/migrations/20220524172636_create_featureflags.exs deleted file mode 100644 index 1fd816fbfe..0000000000 --- a/src/featureflagservice/priv/repo/migrations/20220524172636_create_featureflags.exs +++ /dev/null @@ -1,50 +0,0 @@ -defmodule Featureflagservice.Repo.Migrations.CreateFeatureflags do - use Ecto.Migration - - def change do - create table(:featureflags) do - add :name, :string - add :description, :string - add :enabled, :float, default: 0.0, null: false - - timestamps() - end - - create unique_index(:featureflags, [:name]) - - execute(&execute_up/0, &execute_down/0) - end - - defp execute_up do - repo().insert(%Featureflagservice.FeatureFlags.FeatureFlag{ - name: "productCatalogFailure", - description: "Fail product catalog service on a specific product", - enabled: 0.0 - }) - - repo().insert(%Featureflagservice.FeatureFlags.FeatureFlag{ - name: "recommendationCache", - description: "Cache recommendations", - enabled: 0.0 - }) - - repo().insert(%Featureflagservice.FeatureFlags.FeatureFlag{ - name: "adServiceFailure", - description: "Fail ad service requests sporadically", - enabled: 0.0 - }) - - repo().insert(%Featureflagservice.FeatureFlags.FeatureFlag{ - name: "cartServiceFailure", - description: "Fail cart service requests sporadically", - enabled: 0.0 - }) - end - - defp execute_down do - repo().delete(%Featureflagservice.FeatureFlags.FeatureFlag{name: "productCatalogFailure"}) - repo().delete(%Featureflagservice.FeatureFlags.FeatureFlag{name: "recommendationCache"}) - repo().delete(%Featureflagservice.FeatureFlags.FeatureFlag{name: "adServiceFailure"}) - repo().delete(%Featureflagservice.FeatureFlags.FeatureFlag{name: "cartServiceFailure"}) - end -end diff --git a/src/featureflagservice/rel/overlays/bin/server b/src/featureflagservice/rel/overlays/bin/server index aa36204cb2..5f5e409674 100755 --- a/src/featureflagservice/rel/overlays/bin/server +++ b/src/featureflagservice/rel/overlays/bin/server @@ -3,6 +3,4 @@ cd -P -- "$(dirname -- "$0")" -./featureflagservice eval Featureflagservice.Release.migrate || { echo "Database setup or migrations failed."; exit 1; } - PHX_SERVER=true exec ./featureflagservice start diff --git a/src/ffs_postgres/Dockerfile b/src/ffs_postgres/Dockerfile new file mode 100644 index 0000000000..8694e54392 --- /dev/null +++ b/src/ffs_postgres/Dockerfile @@ -0,0 +1,4 @@ +FROM postgres:16.1 +WORKDIR /app +COPY ./src/ffs_postgres/init.sh /docker-entrypoint-initdb.d +COPY ./src/ffs_postgres/dump.sql ./dump.sql diff --git a/src/ffs_postgres/dump.sql b/src/ffs_postgres/dump.sql new file mode 100644 index 0000000000..71bf31d5de --- /dev/null +++ b/src/ffs_postgres/dump.sql @@ -0,0 +1,106 @@ +-- +-- PostgreSQL database dump +-- + +-- Dumped from database version 16.1 (Debian 16.1-1.pgdg120+1) +-- Dumped by pg_dump version 16.1 + +SET statement_timeout = 0; +SET lock_timeout = 0; +SET idle_in_transaction_session_timeout = 0; +SET client_encoding = 'UTF8'; +SET standard_conforming_strings = on; +SELECT pg_catalog.set_config('search_path', '', false); +SET check_function_bodies = false; +SET xmloption = content; +SET client_min_messages = warning; +SET row_security = off; + +SET default_tablespace = ''; + +SET default_table_access_method = heap; + +-- +-- Name: featureflags; Type: TABLE; Schema: public; Owner: ffs +-- + +CREATE TABLE public.featureflags ( + id bigint NOT NULL, + name character varying(255), + description character varying(255), + enabled double precision DEFAULT 0.0 NOT NULL, + inserted_at timestamp(0) without time zone NOT NULL, + updated_at timestamp(0) without time zone NOT NULL +); + + +ALTER TABLE public.featureflags OWNER TO ffs; + +-- +-- Name: featureflags_id_seq; Type: SEQUENCE; Schema: public; Owner: ffs +-- + +CREATE SEQUENCE public.featureflags_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER SEQUENCE public.featureflags_id_seq OWNER TO ffs; + +-- +-- Name: featureflags_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: ffs +-- + +ALTER SEQUENCE public.featureflags_id_seq OWNED BY public.featureflags.id; + + +ALTER TABLE public.schema_migrations OWNER TO ffs; + +-- +-- Name: featureflags id; Type: DEFAULT; Schema: public; Owner: ffs +-- + +ALTER TABLE ONLY public.featureflags ALTER COLUMN id SET DEFAULT nextval('public.featureflags_id_seq'::regclass); + + +-- +-- Data for Name: featureflags; Type: TABLE DATA; Schema: public; Owner: ffs +-- + +COPY public.featureflags (id, name, description, enabled, inserted_at, updated_at) FROM stdin; +1 productCatalogFailure Fail product catalog service on a specific product 0 2024-01-07 20:06:29 2024-01-07 20:06:29 +2 recommendationCache Cache recommendations 0 2024-01-07 20:06:29 2024-01-07 20:06:29 +3 adServiceFailure Fail ad service requests sporadically 0 2024-01-07 20:06:29 2024-01-07 20:06:29 +4 cartServiceFailure Fail cart service requests sporadically 0 2024-01-07 20:06:29 2024-01-07 20:06:29 +\. + + +-- +-- Name: featureflags_id_seq; Type: SEQUENCE SET; Schema: public; Owner: ffs +-- + +SELECT pg_catalog.setval('public.featureflags_id_seq', 4, true); + + +-- +-- Name: featureflags featureflags_pkey; Type: CONSTRAINT; Schema: public; Owner: ffs +-- + +ALTER TABLE ONLY public.featureflags + ADD CONSTRAINT featureflags_pkey PRIMARY KEY (id); + + +-- +-- Name: featureflags_name_index; Type: INDEX; Schema: public; Owner: ffs +-- + +CREATE UNIQUE INDEX featureflags_name_index ON public.featureflags USING btree (name); + + +-- +-- PostgreSQL database dump complete +-- + diff --git a/src/ffs_postgres/init.sh b/src/ffs_postgres/init.sh new file mode 100644 index 0000000000..23f1ecbafa --- /dev/null +++ b/src/ffs_postgres/init.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +psql -U $POSTGRES_USER -d $POSTGRES_DB -a -f /app/dump.sql +