Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add seed cli image #1

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion scripts/cli-migrations/v3/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
cli-hasura-linux-amd64
manifest.yaml
8 changes: 7 additions & 1 deletion scripts/cli-migrations/v3/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ ARG SERVER_IMAGE_TAG

FROM hasura/graphql-engine:${SERVER_IMAGE_TAG}

## Use the following image for ARM
# FROM fedormelexin/graphql-engine-arm64:${SERVER_IMAGE_TAG}

RUN apt-get update && apt-get install -y netcat

# set an env var to let the cli know that
Expand All @@ -11,6 +14,9 @@ ENV HASURA_GRAPHQL_SHOW_UPDATE_NOTIFICATION=false
COPY docker-entrypoint.sh /bin/
COPY cli-hasura-linux-amd64 /bin/hasura-cli

## Use the following image for ARM
# COPY cli-hasura-linux-arm64 /bin/hasura-cli

RUN chmod +x /bin/hasura-cli

# set an env var to let the cli know that
Expand All @@ -19,4 +25,4 @@ ENV HASURA_GRAPHQL_CLI_ENVIRONMENT=server-on-docker

ENTRYPOINT ["docker-entrypoint.sh"]

CMD ["graphql-engine", "serve"]
# CMD ["graphql-engine", "serve"]
21 changes: 21 additions & 0 deletions scripts/cli-migrations/v3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,24 @@ If it has been stored in a directory other than the default then it can be confi
- `HASURA_GRAPHQL_MIGRATIONS_SERVER_TIMEOUT` (default=`30s`)

Specify the server timeout threshold.

## Devfolio Specific

### How to publish AMD64 image

```
docker build --build-arg SERVER_IMAGE_TAG=v2.0.8 --no-cache -t ghcr.io/devfolioco/graphql-engine:v2.0.8.cli-migrations-v3-amd64 .

docker push ghcr.io/devfolioco/graphql-engine:v2.0.8.cli-migrations-v3-amd64

```

### How to publish ARM64 image

Make sure the code in the Dockerfile is configured to use the ARM64 files and ARM64 version of Hasura

```
docker build --build-arg SERVER_IMAGE_TAG=v2.0.8 --no-cache -t ghcr.io/devfolioco/graphql-engine:v2.0.8.cli-migrations-v3-arm64 .

docker push ghcr.io/devfolioco/graphql-engine:v2.0.8.cli-migrations-v3-arm64
```
Binary file added scripts/cli-migrations/v3/cli-hasura-linux-amd64
Binary file not shown.
Binary file added scripts/cli-migrations/v3/cli-hasura-linux-arm64
Binary file not shown.
38 changes: 30 additions & 8 deletions scripts/cli-migrations/v3/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ log() {

DEFAULT_MIGRATIONS_DIR="/hasura-migrations"
DEFAULT_METADATA_DIR="/hasura-metadata"
DEFAULT_SEEDS_DIR="/hasura-seeds"
TEMP_PROJECT_DIR="/tmp/hasura-project"

# Use 9691 port for running temporary instance.
Expand Down Expand Up @@ -62,6 +63,27 @@ if [ -z ${HASURA_GRAPHQL_METADATA_DIR+x} ]; then
HASURA_GRAPHQL_METADATA_DIR="$DEFAULT_METADATA_DIR"
fi

# check if seeds directory is set, default otherwise
if [ -z ${HASURA_GRAPHQL_SEEDS_DIR+x} ]; then
log "migrations-startup" "env var HASURA_GRAPHQL_SEEDS_DIR is not set, defaulting to $DEFAULT_SEEDS_DIR"
HASURA_GRAPHQL_SEEDS_DIR="$DEFAULT_SEEDS_DIR"
fi

# apply migrations if the directory exist
if [ -d "$HASURA_GRAPHQL_MIGRATIONS_DIR" ]; then
log "migrations-apply" "applying migrations from $HASURA_GRAPHQL_MIGRATIONS_DIR"
mkdir -p "$TEMP_PROJECT_DIR"
cp -a "$HASURA_GRAPHQL_MIGRATIONS_DIR/." "$TEMP_PROJECT_DIR/migrations/"
cd "$TEMP_PROJECT_DIR"
echo "version: 3" > config.yaml
echo "endpoint: http://localhost:$HASURA_GRAPHQL_MIGRATIONS_SERVER_PORT" >> config.yaml
hasura-cli migrate apply --all-databases
log "migrations-apply" "reloading metadata"
hasura-cli metadata reload
else
log "migrations-apply" "directory $HASURA_GRAPHQL_MIGRATIONS_DIR does not exist, skipping migrations"
fi

# apply metadata if the directory exist
if [ -d "$HASURA_GRAPHQL_METADATA_DIR" ]; then
rm -rf "TEMP_PROJECT_DIR"
Expand All @@ -77,19 +99,19 @@ else
log "migrations-apply" "directory $HASURA_GRAPHQL_METADATA_DIR does not exist, skipping metadata"
fi

# apply migrations if the directory exist
if [ -d "$HASURA_GRAPHQL_MIGRATIONS_DIR" ]; then
log "migrations-apply" "applying migrations from $HASURA_GRAPHQL_MIGRATIONS_DIR"
# apply seeds if the directory exist
if [ -d "$HASURA_GRAPHQL_SEEDS_DIR" ]; then
log "seeds-apply" "applying seeds from $HASURA_GRAPHQL_SEEDS_DIR"
mkdir -p "$TEMP_PROJECT_DIR"
cp -a "$HASURA_GRAPHQL_MIGRATIONS_DIR/." "$TEMP_PROJECT_DIR/migrations/"
cp -a "$HASURA_GRAPHQL_SEEDS_DIR/." "$TEMP_PROJECT_DIR/seeds/"
cd "$TEMP_PROJECT_DIR"
echo "version: 3" > config.yaml
echo "endpoint: http://localhost:$HASURA_GRAPHQL_MIGRATIONS_SERVER_PORT" >> config.yaml
hasura-cli migrate apply --all-databases
log "migrations-apply" "reloading metadata"
hasura-cli metadata reload
hasura-cli seed apply --database-name default
# log "seeds-apply" "reloading metadata"
# hasura-cli metadata reload
else
log "migrations-apply" "directory $HASURA_GRAPHQL_MIGRATIONS_DIR does not exist, skipping migrations"
log "seeds-apply" "directory $HASURA_GRAPHQL_SEEDS_DIR does not exist, skipping seeds"
fi

# kill graphql engine that we started earlier
Expand Down