-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from OkieOth/recover_for_all
Recover for all
- Loading branch information
Showing
10 changed files
with
165 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Publish docker image | ||
|
||
on: | ||
push: | ||
tags: | ||
- '[0-9]+.[0-9]+.[0-9]+' # Push events to matching v*, i.e. v1.0, v20.15.10 | ||
|
||
jobs: | ||
publish: | ||
name: Publish | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
- name: build image | ||
run: ./buildImage.sh | ||
- name: Login to GitHub Registry | ||
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u okieoth --password-stdin | ||
- name: Push the Docker image | ||
run: docker push ghcr.io/okieoth/mschemaguesser:`cat version.txt | grep -P '\d+\.\d+\.\d+'` | ||
- name: Push the latest Docker image | ||
run: docker push ghcr.io/okieoth/mschemaguesser | ||
- name: Create Release | ||
id: create_release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: ${{ github.ref }} | ||
release_name: ${{ github.ref }} | ||
body_path: CHANGELOG.md | ||
draft: false | ||
prerelease: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,5 @@ go.work | |
|
||
tmp.* | ||
test.* | ||
tmp | ||
tmp | ||
mschemaguesser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# 1.0.0 | ||
* main functionality is implemented | ||
* CI releases docker image on github |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
FROM golang:1.21 AS builder | ||
|
||
WORKDIR /app | ||
|
||
COPY go.mod go.sum ./ | ||
RUN go mod download | ||
|
||
COPY cmd ./cmd | ||
COPY internal ./internal | ||
COPY resources ./resources | ||
|
||
RUN go test -v --skip "_IT" ./... | ||
|
||
RUN CGO_ENABLED=0 GOOS=linux go build -o mschemaguesser cmd/schemaguesser/main.go | ||
|
||
FROM alpine:latest | ||
|
||
WORKDIR /app | ||
|
||
COPY --from=builder /app/mschemaguesser . | ||
COPY --from=builder /app/resources/json_schema.tmpl ./resources/json_schema.tmpl | ||
|
||
ENTRYPOINT [ "./mschemaguesser" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,75 @@ | ||
[![ci](https://github.com/OkieOth/mschemaguesser/actions/workflows/test.yml/badge.svg)](https://github.com/OkieOth/mschemaguesser/actions/workflows/test.yml) | ||
![WIP](https://img.shields.io/badge/work%20in%20progress-red) | ||
|
||
# TL;DR; | ||
|
||
Tool to guess storage models from mongodb | ||
|
||
```bash | ||
# show help | ||
go run cmd/schemaguesser/main.go help | ||
![Basic usage](img/usage_help.png) | ||
|
||
# Usage | ||
|
||
If you have a mongodb installation by hand than you can use this. In | ||
case you don't the repo contained docker compose stack is a good | ||
starting point. | ||
|
||
```bash | ||
# start test environment with Mongodb | ||
./docker/bin/compose_env.sh start | ||
``` | ||
|
||
The default connection string is | ||
`mongodb://{MONGO_USER}:{MONGO_PASSWORD}@{MONGO_HOST}:{MONGO_PORT}/admin` | ||
|
||
It can be customized with the following environment variables: | ||
* MONGO_USER - User to authenticate, if not set then `admin` | ||
* MONGO_PASSWORD - Password to authenticate, if not set then `secretpassword` | ||
* MONGO_HOST - IP address or server name to mongodb, if not set then `localhost` | ||
* MONGO_PORT - port that is used, if not set then `27017` | ||
|
||
In cases where it isn't enough to customize the env variables the commandline | ||
switch `--con_str` can be used to provide a suitable connection string to the | ||
program. | ||
|
||
|
||
## Native | ||
```bash | ||
go build -o mschemaguesser cmd/schemaguesser/main.go | ||
|
||
# print usage | ||
./mschemaguesser --help | ||
|
||
# query all existing databases | ||
# in general MONGO_HOST can be skipped in case of localhost connections | ||
MONGO_HOST=localhost ./mschemaguesser list databases | ||
|
||
# export the schemas of all databases and their collections | ||
# in general MONGO_HOST can be skipped in case of localhost connections | ||
MONGO_HOST=localhost ./mschemaguesser schema --database all --output /tmp | ||
``` | ||
|
||
## Docker | ||
|
||
```bash | ||
# print usage | ||
docker run -u $(id -u ${USER}):$(id -g ${USER}) --rm \ | ||
-e MONGO_HOST=192.168.178.52 \ | ||
ghcr.io/okieoth/mschemaguesser --help | ||
|
||
# query all existing databases | ||
docker run -u $(id -u ${USER}):$(id -g ${USER}) --rm \ | ||
-e MONGO_HOST=192.168.178.52 \ | ||
ghcr.io/okieoth/mschemaguesser list databases | ||
|
||
# export the schemas of all databases and their collections | ||
docker run -u $(id -u ${USER}):$(id -g ${USER}) --rm \ | ||
-v $(pwd)/tmp:/output_dir \ | ||
-e MONGO_HOST=192.168.178.52 \ | ||
ghcr.io/okieoth/mschemaguesser schema \ | ||
--database all --output /output_dir | ||
``` | ||
|
||
```bash | ||
# show help | ||
go run cmd/schemaguesser/main.go help | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/bash | ||
|
||
scriptPos=${0%/*} | ||
|
||
|
||
imageBase=ghcr.io/okieoth/mschemaguesser | ||
imageTag=`cat $scriptPos/version.txt | grep -P '\d+\.\d+\.\d+'` | ||
|
||
imageName="$imageBase:$imageTag" | ||
|
||
echo "I am going to create: $imageName" | ||
|
||
pushd "$scriptPos" > /dev/null | ||
if docker build -f Dockerfile.release -t $imageName . | ||
then | ||
docker tag $imageName $imageBase | ||
echo -en "\033[1;34m image created: $imageName, $imageBase \033[0m\n" | ||
else | ||
echo -en "\033[1;31m error while create image: $imageName \033[0m\n" | ||
fi | ||
popd > /dev/null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1.0.0 |