Skip to content

Commit

Permalink
Implement Docker Compose for Project Deployment (#1330)
Browse files Browse the repository at this point in the history
* Adding docker compose deployment

* modified

* modified

* Fixed docker compose env issue

* Update docker-compose.yml

* Update docker-compose.yml
  • Loading branch information
shubh7791 authored Jul 11, 2024
1 parent 80c5ea3 commit 4d5cd10
Show file tree
Hide file tree
Showing 7 changed files with 375 additions and 1 deletion.
10 changes: 10 additions & 0 deletions db-docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM postgres:latest

COPY schema.sql /docker-entrypoint-initdb.d/

VOLUME /var/lib/postgresql/data

EXPOSE 5432

# Start the PostgreSQL server
CMD ["postgres"]
220 changes: 220 additions & 0 deletions db-docker/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
--
-- PostgreSQL database dump
--

-- Dumped from database version 12.12 (Ubuntu 12.12-0ubuntu0.20.04.1)
-- Dumped by pg_dump version 12.12 (Ubuntu 12.12-0ubuntu0.20.04.1)

-- Started on 2022-09-24 20:18:09 IST

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;

--
-- TOC entry 626 (class 1247 OID 16424)
-- Name: transaction_status; Type: TYPE; Schema: public; Owner: -
--

CREATE TYPE public.transaction_status AS ENUM (
'PENDING',
'SUCCESS',
'FAILED'
);


--
-- TOC entry 637 (class 1247 OID 16868)
-- Name: tx_status; Type: TYPE; Schema: public; Owner: -
--

CREATE TYPE public.tx_status AS ENUM (
'SUCCESS',
'PENDING',
'FAILED'
);


SET default_table_access_method = heap;

--
-- TOC entry 204 (class 1259 OID 16822)
-- Name: multisig_accounts; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.multisig_accounts (
address character varying(50) NOT NULL,
threshold integer NOT NULL,
chain_id character varying(20) NOT NULL,
pubkey_type character varying(50) NOT NULL,
name character varying(100) NOT NULL,
created_by character varying(50) NOT NULL,
created_at timestamp with time zone DEFAULT '2022-09-23 22:26:53.911454+05:30'::timestamp with time zone NOT NULL
);

--
-- TOC entry 204 (class 1259 OID 16822)
-- Name: users; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.users (
id SERIAL PRIMARY KEY,
address character varying(100) NOT NULL,
salt INTEGER CHECK (salt > 0),
signature character varying(250) NOT NULL,
pub_key jsonb DEFAULT '[]'::jsonb,
created_at timestamp with time zone DEFAULT '2022-09-23 22:26:53.911454+05:30'::timestamp with time zone NOT NULL
);


--
-- TOC entry 205 (class 1259 OID 16840)
-- Name: pubkeys; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.pubkeys (
address character varying(50) NOT NULL,
multisig_address character varying(50) NOT NULL,
pubkey jsonb NOT NULL
);


--
-- TOC entry 207 (class 1259 OID 16877)
-- Name: transactions; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.transactions (
id integer NOT NULL,
multisig_address character varying(50) NOT NULL,
fee jsonb,
status public.tx_status DEFAULT 'PENDING'::public.tx_status NOT NULL,
messages jsonb DEFAULT '[]'::jsonb,
hash text DEFAULT ''::text,
err_msg text DEFAULT ''::text,
memo text DEFAULT ''::text,
signatures jsonb DEFAULT '[]'::jsonb,
last_updated timestamp with time zone DEFAULT '2022-09-23 22:26:53.911454+05:30'::timestamp with time zone NOT NULL,
created_at timestamp with time zone DEFAULT '2022-09-23 22:27:24.815343+05:30'::timestamp with time zone NOT NULL
);

--
-- TOC entry 206 (class 1259 OID 16444)
-- Name: price_info; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.price_info (
denom character varying(50) NOT NULL,
coingecko_name character varying(50) NOT NULL,
enabled boolean DEFAULT true NOT NULL,
last_updated timestamp with time zone,
info jsonb DEFAULT '{}'::jsonb
);


--
-- TOC entry 2969 (class 0 OID 16444)
-- Dependencies: 206
-- Data for Name: price_info; Type: TABLE DATA; Schema: public; Owner: -
--

COPY public.price_info (denom, coingecko_name, enabled, last_updated, info) FROM stdin;
uatom cosmos t 2022-10-04 09:10:29.043476+00 {}
uregen regen t 2022-10-04 09:10:29.043476+00 {}
uosmo osmosis t 2022-10-04 09:10:29.043476+00 {}
ujuno juno-network t 2022-10-04 09:10:29.043476+00 {}
ustars stargaze t 2022-10-04 09:10:29.043476+00 {}
uakt akash-network t 2022-10-04 09:10:29.043476+00 {}
\.



--
-- TOC entry 206 (class 1259 OID 16875)
-- Name: transactions_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE public.transactions_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;


--
-- TOC entry 3005 (class 0 OID 0)
-- Dependencies: 206
-- Name: transactions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE public.transactions_id_seq OWNED BY public.transactions.id;


--
-- TOC entry 2857 (class 2604 OID 16880)
-- Name: transactions id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.transactions ALTER COLUMN id SET DEFAULT nextval('public.transactions_id_seq'::regclass);


--
-- TOC entry 2867 (class 2606 OID 16952)
-- Name: multisig_accounts multisig_accounts_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.multisig_accounts
ADD CONSTRAINT multisig_accounts_pkey PRIMARY KEY (address);


--
-- TOC entry 2869 (class 2606 OID 17014)
-- Name: pubkeys pubkeys_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.pubkeys
ADD CONSTRAINT pubkeys_pkey PRIMARY KEY (address, multisig_address);


--
-- TOC entry 2871 (class 2606 OID 16890)
-- Name: transactions transactions_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.transactions
ADD CONSTRAINT transactions_pkey PRIMARY KEY (id);


--
-- TOC entry 2872 (class 2606 OID 17015)
-- Name: pubkeys pubkeys_multisig_address_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.pubkeys
ADD CONSTRAINT pubkeys_multisig_address_fkey FOREIGN KEY (multisig_address) REFERENCES public.multisig_accounts(address);


--
-- TOC entry 2873 (class 2606 OID 17028)
-- Name: transactions transactions_multisig_address_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.transactions
ADD CONSTRAINT transactions_multisig_address_fkey FOREIGN KEY (multisig_address) REFERENCES public.multisig_accounts(address);


-- Completed on 2022-09-24 20:18:09 IST

--
-- PostgreSQL database dump complete
--

52 changes: 52 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
version: '3.8'

services:
frontend:
build:
context: ./frontend
args:
NEXT_PUBLIC_APP_API_URI: http://${HOST_IP}:1323
ports:
- "3000:3000"
depends_on:
backend:
condition: service_healthy
networks:
- my_network

backend:
build:
context: ./server
ports:
- "1323:1323"
depends_on:
database:
condition: service_healthy
networks:
- my_network
healthcheck:
test: ["CMD", "curl", "-f", "http://backend:1323"]
interval: 30s
timeout: 10s
retries: 3

database:
build:
context: ./db-docker
ports:
- "5432:5432"
environment:
- POSTGRES_DB=multisig
- POSTGRES_USER=alice
- POSTGRES_PASSWORD=password
networks:
- my_network
healthcheck:
test: ["CMD", "pg_isready", "-U", "alice", "-d", "multisig", "-h", "localhost"]
interval: 30s
timeout: 10s
retries: 3

networks:
my_network:
driver: bridge
56 changes: 56 additions & 0 deletions docker_compose_README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

# Docker Compose Deployment Instructions

This document provides the necessary steps to deploy the application using Docker Compose.

## Prerequisites

- Ensure Docker and Docker Compose are installed on your system.

## Steps to Deploy the Application

### 1. Export Host IP Address

First, you need to export your host IP address as an environment variable. This will be used in the Docker Compose file.

Open your terminal and run the following command:

```sh
export HOST_IP=$(hostname -I | awk '{print $1}')
```

This command fetches the IP address of your host machine and stores it in the `HOST_IP` environment variable.

### 2. Run Docker Compose

After exporting the `HOST_IP` variable, you can start the application using Docker Compose. Run the following command:

```sh
docker compose up -d
```

The `-d` flag tells Docker Compose to run the containers in detached mode, meaning they will run in the background.

### 3. Verify the Deployment

To verify that the containers are running, use the following command:

```sh
docker ps
```

This will list all running containers. You should see the containers defined in your `docker-compose.yml` file listed here.

### 4. Access the Application

Once the containers are running, you can access the application through your web browser or any other client as per the service configuration in your `docker-compose.yml`.

### 5. Stopping the Application

To stop and remove the running containers, use the following command:

```sh
docker compose down
```

This will stop the containers and remove them along with any networks created by Docker Compose.
19 changes: 19 additions & 0 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM node:lts AS build

WORKDIR /app

COPY package.json ./

RUN yarn install --frozen-lockfile

COPY . .

ARG NEXT_PUBLIC_APP_API_URI

ENV NEXT_PUBLIC_APP_API_URI=${NEXT_PUBLIC_APP_API_URI}

RUN yarn build

EXPOSE 3000

CMD ["yarn", "start"]
17 changes: 17 additions & 0 deletions server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM golang:1.21

WORKDIR /app

COPY go.mod .
COPY go.sum .
COPY . .

RUN go mod tidy

EXPOSE 1323

RUN ["cp", "example.yaml", "config.yaml"]

RUN go build -o app

CMD ["./app"]
2 changes: 1 addition & 1 deletion server/example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ production:

dev:
database:
host: "localhost"
host: "database"
port: 5432
user: "alice"
password: "password"
Expand Down

0 comments on commit 4d5cd10

Please sign in to comment.