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

fix: docker build command in GitHub Actions config #90

Merged
merged 4 commits into from
Mar 30, 2022
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
9 changes: 4 additions & 5 deletions .github/workflows/docker-build-and-push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ env:
GITHUB_SHA: ${{ github.sha }}
GITHUB_REF: ${{ github.ref }}
IMAGE: pgadapter
REGISTRY_HOSTNAME: us-west1-docker.pkg.dev/cloud-spanner-pg-adapter/pgadapter
REGISTRY_HOSTNAME: us-west1-docker.pkg.dev/cloud-spanner-pg-adapter/pgadapter-docker-images

jobs:
setup-build-publish-deploy:
Expand All @@ -32,17 +32,16 @@ jobs:
uses: 'google-github-actions/setup-gcloud@v0'

# Configure docker to use the gcloud command-line tool as a credential helper
- run: gcloud auth configure-docker us-west1-docker.pkg.dev
- run: gcloud auth configure-docker gcr.io,us-west1-docker.pkg.dev

# Build the Docker image
- name: Build
run: |
export TAG=`echo $GITHUB_REF | awk -F/ '{print $NF}'`
echo $TAG
docker build . -t "$REGISTRY_HOSTNAME"/"$IMAGE":"$TAG" \
-f build/Dockerfile \
docker build . -f build/Dockerfile -t "$REGISTRY_HOSTNAME"/"$IMAGE":"$TAG" \
--build-arg GITHUB_SHA="$GITHUB_SHA" \
--build-arg GITHUB_REF="$GITHUB_REF" .
--build-arg GITHUB_REF="$GITHUB_REF"

# Push the Docker image to Google Artifact Registry
- name: Publish
Expand Down
105 changes: 55 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,30 @@ not supported:
COPY <table_name> FROM STDIN is supported.

## Usage
The PostgreSQL adapter can be started both as a standalone process as well as an
in-process server.
The PostgreSQL adapter can be started both as a Docker container, a standalone process as well as an in-process server.


### Docker

Replace the project, instance and database names and the credentials file in the example below to
run PGAdapter from a pre-built Docker image.

```shell
docker pull us-west1-docker.pkg.dev/cloud-spanner-pg-adapter/pgadapter-docker-images/pgadapter
docker run \
-d -p 5432:5432 \
-v /local/path/to/credentials.json:/tmp/keys/key.json:ro \
-e GOOGLE_APPLICATION_CREDENTIALS=/tmp/keys/key.json \
us-west1-docker.pkg.dev/cloud-spanner-pg-adapter/pgadapter/pgadapter \
-p my-project -i my-instance -d my-database \
-x
```

The option `-v /local/path/to/credentials.json:/tmp/keys/key.json:ro` mounts the credentials file on
your local system to a file in the Docker container. The `-e GOOGLE_APPLICATION_CREDENTIALS=/tmp/keys/key.json`
sets the file as the default credentials to use inside the container.

See [Options](#Options) for an explanation of all further options.

### Standalone
1. Build a jar file containing all dependencies by running `mvn package -P shade`.
Expand All @@ -54,6 +76,37 @@ in-process server.
java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter
```

### In-process
1. Add google-cloud-spanner-pgadapter as a dependency to your project.
2. Build a server using the `com.google.cloud.spanner.pgadapter.ProxyServer`
class:

```java
class PGProxyRunner {
public static void main() {
ProxyServer server = new ProxyServer(
new OptionsMetadata(
"jdbc:cloudspanner:/projects/my-project-name"
+ "/instances/my-instance-id"
+ "/databases/my-database-name"
+ ";credentials=/home/user/service-account-credentials.json",
portNumber,
textFormat,
forceBinary,
authenticate,
requiresMatcher,
commandMetadataJSON)
);
server.startServer();
}
}
```

Wherein the first item is the JDBC connection string containing pertinent
information regarding project id, instance id, database name, credentials file
path; All other items map directly to previously mentioned CLI options.

### Options
The following options are required to run the proxy:

```
Expand Down Expand Up @@ -173,54 +226,6 @@ java -jar <jar-file> -p <project name> -i <instance id> -d <database name> -c
<path to credentials file> -s 5432
```

#### Standalone through docker

1. Build the docker image:

```
docker build . -t "pgadapter" -f build/Dockerfile

```

2. Run the docker image with environment variables set:

```
docker run -d -p 127.0.0.1:HOST-PORT:DOCKER-PORT \
-v CREDENTIALS_FILE_PATH:/acct_credentials.json pgadapter:latest \
-p PROJECT -i INSTANCE -d DATABASE \
-c /acct_credentials.json -q -x OTHER_OPTIONS
```

### In-process
1. Add google-cloud-spanner-pgadapter as a dependency to your project.
2. Build a server using the `com.google.cloud.spanner.pgadapter.ProxyServer`
class:

```java
class PGProxyRunner {
public static void main() {
ProxyServer server = new ProxyServer(
new OptionsMetadata(
"jdbc:cloudspanner:/projects/my-project-name"
+ "/instances/my-instance-id"
+ "/databases/my-database-name"
+ ";credentials=/home/user/service-account-credentials.json",
portNumber,
textFormat,
forceBinary,
authenticate,
requiresMatcher,
commandMetadataJSON)
);
server.startServer();
}
}
```

Wherein the first item is the JDBC connection string containing pertinent
information regarding project id, instance id, database name, credentials file
path; All other items map directly to previously mentioned CLI options.

## COPY support
`COPY <table-name> FROM STDIN` is supported. This option can be used to insert bulk data to a Cloud
Spanner database. `COPY` operations are atomic by default, but the standard transaction limits of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class OptionsMetadata {
private static final String OPTION_COMMAND_METADATA_FILE = "j";
private static final String OPTION_DISABLE_LOCALHOST_CHECK = "x";
private static final String CLI_ARGS =
"gcpga -p <project> -i <instance> -d <database> -c <credentials_file>";
"pgadapter -p <project> -i <instance> -d <database> -c <credentials_file>";
private static final String OPTION_HELP = "h";
private static final String DEFAULT_PORT = "5432";
private static final int MIN_PORT = 0, MAX_PORT = 65535;
Expand Down