Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 360d470

Browse files
Merge pull request #39 from decentraland/feat/change-service-to-just-export-api
feat: modify Dockerfile to run just the API
2 parents 1525283 + 522f8de commit 360d470

File tree

3 files changed

+54
-33
lines changed

3 files changed

+54
-33
lines changed

Dockerfile

-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ COPY --from=builder /squid/squid.yaml squid.yaml
3737
ADD commands.json .
3838
RUN echo -e "loglevel=silent\\nupdate-notifier=false" > /squid/.npmrc
3939
RUN npm i -g @subsquid/cli@latest && mv $(which sqd) /usr/local/bin/sqd
40-
ENV ETH_PROMETHEUS_PORT 3000
41-
ENV POLYGON_PROMETHEUS_PORT 3001
4240
ENV GQL_PORT 5000
4341

4442
RUN apk update && apk add --no-cache tini postgresql-client curl

entrypoint.sh

+3-31
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,15 @@
11
#!/bin/sh
22

3-
# Generate a unique schema name and user credentials using a timestamp
4-
CURRENT_TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
5-
NEW_SCHEMA_NAME="marketplace_squid_${CURRENT_TIMESTAMP}"
6-
NEW_DB_USER="marketplace_squid_user_${CURRENT_TIMESTAMP}"
7-
83
# Check if required environment variables are set
94
if [ -z "$DB_USER" ] || [ -z "$DB_NAME" ] || [ -z "$DB_PASSWORD" ] || [ -z "$DB_HOST" ] || [ -z "$DB_PORT" ]; then
105
echo "Error: Required environment variables are not set."
116
echo "Ensure DB_USER, DB_NAME, DB_PASSWORD, DB_HOST, and DB_PORT are set."
127
exit 1
138
fi
149

15-
# Log the generated variables
16-
echo "Generated schema name: $NEW_SCHEMA_NAME"
17-
echo "Generated user: $NEW_DB_USER"
18-
19-
# Set PGPASSWORD to handle password prompt
20-
export PGPASSWORD=$DB_PASSWORD
21-
22-
# Connect to the database and create the new schema and user
23-
psql -v ON_ERROR_STOP=1 --username "$DB_USER" --dbname "$DB_NAME" --host "$DB_HOST" --port "$DB_PORT" <<-EOSQL
24-
CREATE SCHEMA $NEW_SCHEMA_NAME;
25-
CREATE USER $NEW_DB_USER WITH PASSWORD '$DB_PASSWORD';
26-
GRANT ALL PRIVILEGES ON SCHEMA $NEW_SCHEMA_NAME TO $NEW_DB_USER;
27-
GRANT ALL PRIVILEGES ON DATABASE $DB_NAME TO $NEW_DB_USER;
28-
ALTER USER $NEW_DB_USER SET search_path TO $NEW_SCHEMA_NAME;
29-
EOSQL
30-
31-
# Unset PGPASSWORD
32-
unset PGPASSWORD
33-
3410
# Construct the DB_URL with the new user
35-
export DB_URL=postgresql://$NEW_DB_USER:$DB_PASSWORD@$DB_HOST:$DB_PORT/$DB_NAME
36-
export DB_SCHEMA=$NEW_SCHEMA_NAME
37-
38-
# Log the constructed DB_URL
39-
echo "Exported DB_SCHEMA: $DB_SCHEMA"
11+
export DB_URL=postgresql://$DB_USER:$DB_PASSWORD@$DB_HOST:$DB_PORT/$DB_NAME
4012

4113
# Start the processor service and the GraphQL server
42-
echo "Starting squid services..."
43-
sqd run .
14+
echo "Starting squid API..."
15+
sqd serve:prod

index.sh

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/sh
2+
3+
# Load environment variables from .env file if it exists
4+
if [ -f .env ]; then
5+
export $(grep -v '^#' .env | xargs)
6+
fi
7+
8+
# Generate a unique schema name and user credentials using a timestamp
9+
CURRENT_TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
10+
NEW_SCHEMA_NAME="marketplace_squid_${CURRENT_TIMESTAMP}"
11+
NEW_DB_USER="marketplace_squid_user_${CURRENT_TIMESTAMP}"
12+
13+
# Check if required environment variables are set
14+
if [ -z "$DB_USER" ] || [ -z "$DB_NAME" ] || [ -z "$DB_PASSWORD" ] || [ -z "$DB_HOST" ] || [ -z "$DB_PORT" ]; then
15+
echo "Error: Required environment variables are not set."
16+
echo "Ensure DB_USER, DB_NAME, DB_PASSWORD, DB_HOST, and DB_PORT are set."
17+
exit 1
18+
fi
19+
20+
# Log the generated variables
21+
echo "Generated schema name: $NEW_SCHEMA_NAME"
22+
echo "Generated user: $NEW_DB_USER"
23+
24+
# Set PGPASSWORD to handle password prompt
25+
export PGPASSWORD=$DB_PASSWORD
26+
27+
# Connect to the database and create the new schema and user
28+
psql -v ON_ERROR_STOP=1 --username "$DB_USER" --dbname "$DB_NAME" --host "$DB_HOST" --port "$DB_PORT" <<-EOSQL
29+
CREATE SCHEMA $NEW_SCHEMA_NAME;
30+
CREATE USER $NEW_DB_USER WITH PASSWORD '$DB_PASSWORD';
31+
GRANT ALL PRIVILEGES ON SCHEMA $NEW_SCHEMA_NAME TO $NEW_DB_USER;
32+
GRANT ALL PRIVILEGES ON DATABASE $DB_NAME TO $NEW_DB_USER;
33+
ALTER USER $NEW_DB_USER SET search_path TO $NEW_SCHEMA_NAME;
34+
EOSQL
35+
36+
# Unset PGPASSWORD
37+
unset PGPASSWORD
38+
39+
# Construct the DB_URL with the new user
40+
export DB_URL=postgresql://$NEW_DB_USER:$DB_PASSWORD@$DB_HOST:$DB_PORT/$DB_NAME
41+
export DB_SCHEMA=$NEW_SCHEMA_NAME
42+
43+
# Log the constructed DB_URL
44+
echo "Exported DB_SCHEMA: $DB_SCHEMA"
45+
46+
# Start the processor service and the GraphQL server, and write logs to a file
47+
LOG_FILE="sqd_run_log_${CURRENT_TIMESTAMP}.txt"
48+
echo "Starting squid services..."
49+
sqd run . > "$LOG_FILE" 2>&1
50+
51+
echo "Logs are being written to $LOG_FILE"

0 commit comments

Comments
 (0)