-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
187e644
commit fe992f3
Showing
5 changed files
with
191 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.git/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FROM postgres:9.4 | ||
|
||
# Add our init script and database seed to the correct folders | ||
ADD seed/init-database.sh /docker-entrypoint-initdb.d/ | ||
ADD seed/astromo.sql /tmp/astromo.sql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,10 @@ | ||
# docker-postgresql | ||
PostgreSQL Docker container | ||
|
||
## Build the container | ||
Build our image using Docker | ||
`docker build -t astromo/postgresql .` | ||
|
||
## Running the container | ||
Run the container using | ||
`docker run --name astromo-postgresql -e POSTGRES_PASSWORD=root -p 5432:5432 -d astromo/postgresql` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
-- | ||
-- PostgreSQL database dump | ||
-- | ||
|
||
SET statement_timeout = 0; | ||
SET lock_timeout = 0; | ||
SET client_encoding = 'UTF8'; | ||
SET standard_conforming_strings = on; | ||
SET check_function_bodies = false; | ||
SET client_min_messages = warning; | ||
|
||
-- | ||
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: | ||
-- | ||
|
||
CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog; | ||
|
||
|
||
-- | ||
-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: | ||
-- | ||
|
||
COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language'; | ||
|
||
|
||
-- | ||
-- Name: pgcrypto; Type: EXTENSION; Schema: -; Owner: | ||
-- | ||
|
||
CREATE EXTENSION IF NOT EXISTS pgcrypto WITH SCHEMA public; | ||
|
||
|
||
-- | ||
-- Name: EXTENSION pgcrypto; Type: COMMENT; Schema: -; Owner: | ||
-- | ||
|
||
COMMENT ON EXTENSION pgcrypto IS 'cryptographic functions'; | ||
|
||
|
||
SET search_path = public, pg_catalog; | ||
|
||
SET default_tablespace = ''; | ||
|
||
SET default_with_oids = false; | ||
|
||
-- | ||
-- Name: users; Type: TABLE; Schema: public; Owner: astromo; Tablespace: | ||
-- | ||
|
||
CREATE TABLE users ( | ||
id integer NOT NULL, | ||
email character varying(255) NOT NULL, | ||
password character varying(255), | ||
first_name character varying(255), | ||
last_name character varying(255), | ||
created_at timestamp with time zone NOT NULL, | ||
updated_at timestamp with time zone NOT NULL | ||
); | ||
|
||
|
||
ALTER TABLE users OWNER TO astromo; | ||
|
||
-- | ||
-- Name: TABLE users; Type: COMMENT; Schema: public; Owner: astromo | ||
-- | ||
|
||
COMMENT ON TABLE users IS 'This is the table containing all Astromo users'; | ||
|
||
|
||
-- | ||
-- Name: users_id_seq; Type: SEQUENCE; Schema: public; Owner: astromo | ||
-- | ||
|
||
CREATE SEQUENCE users_id_seq | ||
START WITH 1 | ||
INCREMENT BY 1 | ||
NO MINVALUE | ||
NO MAXVALUE | ||
CACHE 1; | ||
|
||
|
||
ALTER TABLE users_id_seq OWNER TO astromo; | ||
|
||
-- | ||
-- Name: users_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: astromo | ||
-- | ||
|
||
ALTER SEQUENCE users_id_seq OWNED BY users.id; | ||
|
||
|
||
-- | ||
-- Name: id; Type: DEFAULT; Schema: public; Owner: astromo | ||
-- | ||
|
||
ALTER TABLE ONLY users ALTER COLUMN id SET DEFAULT nextval('users_id_seq'::regclass); | ||
|
||
|
||
-- | ||
-- Data for Name: users; Type: TABLE DATA; Schema: public; Owner: astromo | ||
-- | ||
|
||
COPY users (id, email, password, first_name, last_name, created_at, updated_at) FROM stdin; | ||
1 gilles@astromo.io $2a$13$dlsWYjpGXbAZAOXpBA4bgeCnYbSQYu8SZ9Am4NyVJfJds3MBz1zJm Gilles De Mey 2015-03-25 00:00:00+01 2015-03-25 00:00:00+01 | ||
\. | ||
|
||
|
||
-- | ||
-- Name: users_id_seq; Type: SEQUENCE SET; Schema: public; Owner: astromo | ||
-- | ||
|
||
SELECT pg_catalog.setval('users_id_seq', 1, true); | ||
|
||
|
||
-- | ||
-- Name: users_email_key; Type: CONSTRAINT; Schema: public; Owner: astromo; Tablespace: | ||
-- | ||
|
||
ALTER TABLE ONLY users | ||
ADD CONSTRAINT users_email_key UNIQUE (email); | ||
|
||
|
||
-- | ||
-- Name: users_pkey; Type: CONSTRAINT; Schema: public; Owner: astromo; Tablespace: | ||
-- | ||
|
||
ALTER TABLE ONLY users | ||
ADD CONSTRAINT users_pkey PRIMARY KEY (id); | ||
|
||
|
||
-- | ||
-- Name: public; Type: ACL; Schema: -; Owner: astromo | ||
-- | ||
|
||
REVOKE ALL ON SCHEMA public FROM PUBLIC; | ||
REVOKE ALL ON SCHEMA public FROM astromo; | ||
GRANT ALL ON SCHEMA public TO astromo; | ||
GRANT ALL ON SCHEMA public TO PUBLIC; | ||
|
||
|
||
-- | ||
-- PostgreSQL database dump complete | ||
-- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/bash | ||
|
||
# Set our variables | ||
: ${DB_SUPER_USER:=postgres} | ||
: ${DB_USER:=astromo} | ||
: ${DB_PASSWORD:=astromo} | ||
: ${DB_NAME:=astromo} | ||
: ${DB_ENCODING:=UTF-8} | ||
: ${DB_PG_DUMP_FILE:=/tmp/astromo.sql} | ||
|
||
# Enable the crypto extension | ||
gosu postgres postgres --single -jE <<-EOSQL | ||
CREATE EXTENSION pgcrypto; | ||
EOSQL | ||
|
||
# Create our user | ||
gosu postgres postgres --single -jE <<-EOSQL | ||
CREATE USER "$DB_USER" WITH PASSWORD '$DB_PASSWORD'; | ||
EOSQL | ||
|
||
# Create our database and set out new user as the owner | ||
gosu postgres postgres --single -jE <<-EOSQL | ||
CREATE DATABASE "$DB_NAME" WITH OWNER="$DB_USER" TEMPLATE=template0 ENCODING='$DB_ENCODING'; | ||
EOSQL | ||
|
||
# Start the server (temporarily) | ||
gosu postgres pg_ctl start -w | ||
|
||
# Import our SQL seed | ||
psql -f ${DB_PG_DUMP_FILE} -d ${DB_NAME} -U ${DB_SUPER_USER} | ||
|
||
# Stop the server | ||
# The main script in the Docker will reboot it again, don't worry | ||
gosu postgres pg_ctl stop -w |