Skip to content

Commit 24a42bf

Browse files
committedFeb 28, 2025·
initial commit
0 parents  commit 24a42bf

File tree

4 files changed

+219
-0
lines changed

4 files changed

+219
-0
lines changed
 

‎.editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_style = space
7+
indent_size = 4
8+
insert_final_newline = false
9+
trim_trailing_whitespace = true
10+
11+
[*.{yml,yaml}]
12+
indent_size = 2

‎.github/workflows/ci.yml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
env:
9+
REGISTRY: ghcr.io
10+
11+
jobs:
12+
docker:
13+
name: Build Docker Image
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: read
17+
packages: write
18+
attestations: write
19+
steps:
20+
- name: Set up QEMU
21+
uses: docker/setup-qemu-action@v3
22+
- name: Set up Docker Buildx
23+
uses: docker/setup-buildx-action@v3
24+
25+
- name: Login to Docker Hub
26+
uses: docker/login-action@v3
27+
with:
28+
registry: ${{ env.REGISTRY }}
29+
username: ${{ github.actor }}
30+
password: ${{ secrets.GITHUB_TOKEN }}
31+
32+
- name: Checkout repository
33+
uses: actions/checkout@v4
34+
35+
- name: Extract metadata (tags, labels) for Docker
36+
id: meta
37+
uses: docker/metadata-action@v5
38+
39+
- name: Build and push
40+
uses: docker/build-push-action@v6
41+
id: push
42+
with:
43+
tags: ${{ env.REGISTRY }}/${{ github.repository }}
44+
labels: ${{ steps.meta.outputs.labels }}
45+
push: ${{ github.event_name != 'pull_request' }}
46+
cache-from: type=gha
47+
cache-to: type=gha,mode=max

‎Dockerfile

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
ARG POSTGRES_VERSION=15
2+
3+
FROM postgres:${POSTGRES_VERSION}-alpine
4+
5+
ARG POSTGRES_VERSION
6+
7+
RUN apk add --no-cache --virtual .deps \
8+
cmake \
9+
make \
10+
git \
11+
pkgconf \
12+
postgresql${POSTGRES_VERSION}-dev \
13+
openssl-dev \
14+
curl-dev \
15+
clang19 \
16+
llvm19 \
17+
&& \
18+
git clone --depth 1 --branch REL-5_5_2 \
19+
https://github.com/EnterpriseDB/mongo_fdw.git \
20+
/usr/local/src/mongo-fdw \
21+
&& \
22+
cd /usr/local/src/mongo-fdw && \
23+
./autogen.sh && \
24+
export PKG_CONFIG_PATH=mongo-c-driver/src/libmongoc/src:mongo-c-driver/src/libbson/src && \
25+
make USE_PGXS=1 && \
26+
make USE_PGXS=1 install && \
27+
apk del .deps

‎docker-compose.yml

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
services:
2+
postgres:
3+
image: postgres-mongo-fdw
4+
build: .
5+
depends_on:
6+
- mongo
7+
ports:
8+
- 5432:5432
9+
environment:
10+
- POSTGRES_USER=postgres
11+
- POSTGRES_PASSWORD=postgres
12+
volumes:
13+
- postgres_data:/var/lib/postgresql/data
14+
configs:
15+
- source: postgres_init_script
16+
target: /docker-entrypoint-initdb.d/99-custom.sh
17+
18+
db-admin:
19+
image: dpage/pgadmin4:8
20+
depends_on:
21+
- postgres
22+
ports:
23+
- 5433:80
24+
environment:
25+
- PGADMIN_DEFAULT_EMAIL=admin@example.org
26+
- PGADMIN_DEFAULT_PASSWORD=admin
27+
volumes:
28+
- postgres_admin_data:/var/lib/pgadmin
29+
configs:
30+
- source: postgres_password
31+
target: /run/secrets/password.txt
32+
- source: postgres_servers
33+
target: /pgadmin4/servers.json
34+
35+
mongo:
36+
image: mongo
37+
ports:
38+
- 27017:27017
39+
environment:
40+
MONGO_INITDB_ROOT_USERNAME: admin
41+
MONGO_INITDB_ROOT_PASSWORD: admin
42+
MONGO_INITDB_DATABASE: app
43+
volumes:
44+
- mongo_data:/data/db
45+
configs:
46+
- source: mongo_init_script
47+
target: /docker-entrypoint-initdb.d/99-custom.js
48+
49+
mongo-admin:
50+
image: mongo-express
51+
restart: always
52+
depends_on:
53+
- mongo
54+
ports:
55+
- 27018:8081
56+
environment:
57+
ME_CONFIG_MONGODB_ADMINUSERNAME: admin
58+
ME_CONFIG_MONGODB_ADMINPASSWORD: admin
59+
ME_CONFIG_MONGODB_URL: mongodb://admin:admin@mongo:27017
60+
ME_CONFIG_BASICAUTH: false
61+
62+
volumes:
63+
postgres_data:
64+
postgres_admin_data:
65+
mongo_data:
66+
67+
configs:
68+
postgres_servers:
69+
content: |
70+
{
71+
"Servers": {
72+
"1": {
73+
"Group": "postgres",
74+
"Name": "postgres",
75+
"Port": 5432,
76+
"Username": "postgres",
77+
"PassFile": "/run/secrets/password.txt",
78+
"Host": "postgres",
79+
"SSLMode": "prefer",
80+
"MaintenanceDB": "postgres"
81+
}
82+
}
83+
}
84+
postgres_password:
85+
content: postgres
86+
postgres_init_script:
87+
content: |
88+
#!/bin/bash
89+
set -e
90+
91+
psql -v ON_ERROR_STOP=1 --username "$$POSTGRES_USER" --dbname "$$POSTGRES_DB" <<-EOSQL
92+
CREATE EXTENSION mongo_fdw;
93+
94+
CREATE SERVER "mongo" FOREIGN DATA WRAPPER mongo_fdw OPTIONS (
95+
address 'mongo',
96+
port '27017',
97+
authentication_database 'admin'
98+
);
99+
100+
CREATE USER MAPPING FOR postgres SERVER "mongo" OPTIONS (
101+
username 'admin',
102+
password 'admin'
103+
);
104+
105+
CREATE FOREIGN TABLE items (
106+
_id name,
107+
name text,
108+
price float
109+
) SERVER "mongo" OPTIONS (
110+
database 'app',
111+
collection 'items'
112+
);
113+
EOSQL
114+
mongo_init_script:
115+
content: |
116+
db.createCollection("items");
117+
db.items.insertMany([
118+
{
119+
_id: new ObjectId(),
120+
name: "Apples",
121+
price: 4.99
122+
},
123+
{
124+
_id: new ObjectId(),
125+
name: "Bananas",
126+
price: 9.99
127+
},
128+
{
129+
_id: new ObjectId(),
130+
name: "Tomatoes",
131+
price: 3.99
132+
},
133+
]);

0 commit comments

Comments
 (0)
Please sign in to comment.