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

Migrate Docker images to ghcr.io #205

Merged
merged 1 commit into from
May 15, 2023
Merged
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
16 changes: 6 additions & 10 deletions docker-image/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,39 @@

# Mongo Seeding Docker Image

[![Docker image version](https://images.microbadger.com/badges/version/pkosiec/mongo-seeding.svg)](https://microbadger.com/images/pkosiec/mongo-seeding)
[![Docker image size](https://images.microbadger.com/badges/image/pkosiec/mongo-seeding.svg)](https://microbadger.com/images/pkosiec/mongo-seeding)
[![Build Status](https://github.com/pkosiec/mongo-seeding/actions/workflows/branch.yaml/badge.svg)](https://github.com/pkosiec/mongo-seeding/actions)

The ultimate Docker image for populating your MongoDB database :rocket:

Define MongoDB documents in JSON, JavaScript or even TypeScript file(s). Import them with an easy-to-use Docker image.

[![Docker image](http://dockeri.co/image/pkosiec/mongo-seeding)](https://hub.docker.com/r/pkosiec/mongo-seeding/)

## Usage

1. Follow the [tutorial](../docs/import-data-definition.md) to define documents and collections to import.
1. Pull the latest stable version of Mongo Seeding image.

```bash
docker pull pkosiec/mongo-seeding:{versionNumber}
docker pull ghcr.io/pkosiec/mongo-seeding:{versionNumber}
```

Check the version number in GitHub releases.

1. Run the image. Mount your directory with input data with `-v {source}:{destination}` parameter. Specify workspace which is a directory containing data import structure. Usually it will be the same directory:

```bash
docker run --rm --network=host -v /absolute/path/to/data/:/absolute/path/to/data/ -w /absolute/path/to/data pkosiec/mongo-seeding
docker run --rm --network=host -v /absolute/path/to/data/:/absolute/path/to/data/ -w /absolute/path/to/data ghcr.io/pkosiec/mongo-seeding
```

Sometimes, in import data files you would like to `import` or `require` other dependencies, like helper functions defined somewhere else or external libraries. In order to resolve them properly in Docker container, you have to to mount the root directory of your project. As a working directory, define exact path for a directory that contains just the import data.

```bash
docker run --rm --network=host -v /absolute/path/to/project/:/absolute/path/to/project -w /absolute/path/to/project/import-data/ pkosiec/mongo-seeding
docker run --rm --network=host -v /absolute/path/to/project/:/absolute/path/to/project -w /absolute/path/to/project/import-data/ ghcr.io/pkosiec/mongo-seeding
```

1. Configure seeding with environmental variables. See the following example:

```bash
docker run --rm --network=host -v /absolute/path/to/examples/:/absolute/path/to/data/ -w /absolute/path/to/data/ -e DB_URI='mongodb://127.0.0.1:27017/mydbname' -e DROP_DATABASE=true pkosiec/mongo-seeding
docker run --rm --network=host -v /absolute/path/to/examples/:/absolute/path/to/data/ -w /absolute/path/to/data/ -e DB_URI='mongodb://127.0.0.1:27017/mydbname' -e DROP_DATABASE=true ghcr.io/pkosiec/mongo-seeding
```

See [Configuration](#configuration) section for details.
Expand All @@ -54,7 +50,7 @@ As with every Docker container, you can override the [entrypoint](https://docs.d
For example, to prevent Mongo Seeding Docker container from exiting after seeding, use the following command:

```bash
docker run --rm --entrypoint="sh" pkosiec/mongo-seeding -c 'seed; sleep infinity'
docker run --rm --entrypoint="sh" ghcr.io/pkosiec/mongo-seeding -c 'seed; sleep infinity'
```

## Docker image customization
Expand All @@ -64,7 +60,7 @@ You can prepare a customized Docker image for data import. It allows you to prep
1. Prepare Dockerfile:

```
FROM pkosiec/mongo-seeding:latest
FROM ghcr.io/pkosiec/mongo-seeding

#
# Copy sample data
Expand Down
4 changes: 2 additions & 2 deletions docker-image/dev.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ RUN npx lerna run build --scope mongo-seeding-cli

FROM node:18-alpine
LABEL org.opencontainers.image.title="Mongo Seeding" \
org.opencontainers.image.description=" The ultimate solution for populating your MongoDB database. " \
org.opencontainers.image.description="The ultimate solution for populating your MongoDB database." \
org.opencontainers.image.url="https://mongo-seeding.kosiec.dev" \
org.opencontainers.image.documentation="https://mongo-seeding.kosiec.dev" \
org.opencontainers.image.source="https://github.com/pkosiec/mongo-seeding.git" \
org.opencontainers.image.source="https://github.com/pkosiec/mongo-seeding" \
org.opencontainers.image.version="dev" \
org.opencontainers.image.licenses="MIT"

Expand Down
4 changes: 2 additions & 2 deletions docker-image/prod.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM node:18-alpine
LABEL org.opencontainers.image.title="Mongo Seeding" \
org.opencontainers.image.description=" The ultimate solution for populating your MongoDB database. " \
org.opencontainers.image.description="The ultimate solution for populating your MongoDB database." \
org.opencontainers.image.url="https://mongo-seeding.kosiec.dev" \
org.opencontainers.image.documentation="https://mongo-seeding.kosiec.dev" \
org.opencontainers.image.source="https://github.com/pkosiec/mongo-seeding.git" \
org.opencontainers.image.source="https://github.com/pkosiec/mongo-seeding" \
org.opencontainers.image.version=${cliVersion} \
org.opencontainers.image.licenses="MIT"

Expand Down
2 changes: 1 addition & 1 deletion examples/custom-docker-image/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM pkosiec/mongo-seeding:3.7.1
FROM ghcr.io/pkosiec/mongo-seeding

WORKDIR /data-import/

Expand Down
2 changes: 1 addition & 1 deletion examples/import-data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ To see the full description of the CLI usage, read the **[Readme](../../cli/READ
Execute the following command:

```bash
docker run --rm --network="host" -e DB_NAME=testing -e REPLACE_ID=true SET_TIMESTAMPS=true -e DROP_DATABASE=true -v /absolute/path/to/examples/import-data/example/:/absolute/path/to/examples/import-data/example/ -w /absolute/path/to/examples/import-data/example/data pkosiec/mongo-seeding
docker run --rm --network="host" -e DB_NAME=testing -e REPLACE_ID=true SET_TIMESTAMPS=true -e DROP_DATABASE=true -v /absolute/path/to/examples/import-data/example/:/absolute/path/to/examples/import-data/example/ -w /absolute/path/to/examples/import-data/example/data ghcr.io/pkosiec/mongo-seeding
```

Replace `/absolute/path/to/` with your absolute path to this cloned repository.
Expand Down
3 changes: 1 addition & 2 deletions scripts/publish-npm-and-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -o nounset # treat unset variables as an error and exit immediately.
set -o errexit # exit immediately when a command fails.
set -E # needs to be set if we want the ERR trap

IMAGE_NAME="pkosiec/mongo-seeding"
IMAGE_NAME="ghcr.io/pkosiec/mongo-seeding"
IMAGE_LATEST_TAG="latest"

set -e
Expand All @@ -26,7 +26,6 @@ docker build -f ./docker-image/prod.Dockerfile --build-arg cliVersion=${IMAGE_VE
echo "Pushing Docker image..."
docker push ${IMAGE_NAME}:${IMAGE_VERSION_TAG}


read -p "Push the Docker image ${IMAGE_VERSION_TAG} as latest (y/n)?" choice
case "$choice" in
y|Y )
Expand Down
Loading