From 44e0affc829a4e89594f194037538bd5e0825d2e Mon Sep 17 00:00:00 2001 From: Sayan Nandan Date: Sat, 8 Aug 2020 20:43:40 +0530 Subject: [PATCH] Enable remote host connections on tsh --- .github/workflows/docker.yml | 73 ++++++------------------------------ Dockerfile | 2 +- cli/src/argparse.rs | 16 +++++++- cli/src/protocol/mod.rs | 5 +-- 4 files changed, 29 insertions(+), 67 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 0a235517..bc07fc7e 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -1,72 +1,21 @@ -name: Build latest docker image +name: Build docker image on: push: - # Publish `next` as Docker `latest` image. branches: - next - # Publish `v1.2.3` tags as releases. - tags: - - v* - -env: - IMAGE_NAME: tdb - jobs: - # Run tests. - # See also https://docs.docker.com/docker-hub/builds/automated-testing/ test: runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Run tests - run: | - if [ -f docker-compose.test.yml ]; then - docker-compose --file docker-compose.test.yml build - docker-compose --file docker-compose.test.yml run sut - else - docker build . --file Dockerfile - fi - - # Push image to GitHub Packages. - # See also https://docs.docker.com/docker-hub/builds/ - push: - # Ensure test job passes before pushing image. - needs: test - - runs-on: ubuntu-latest - if: github.event_name == 'push' - steps: - - uses: actions/checkout@v2 - - - name: Build image - run: docker build . --file Dockerfile --tag $IMAGE_NAME - - - name: Log into registry - run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin - - - name: Push image - run: | - IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME - - # Change all uppercase to lowercase - IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') - - # Strip git ref prefix from version - VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') - - # Strip "v" prefix from tag name - [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') - - # Use Docker `latest` tag convention - [ "$VERSION" == "next" ] && VERSION=latest - - echo IMAGE_ID=$IMAGE_ID - echo VERSION=$VERSION - - docker tag $IMAGE_NAME $IMAGE_ID:$VERSION - docker push $IMAGE_ID:$VERSION + - name: Checkout code + uses: actions/checkout@v2 + + - name: Build and push Docker images + uses: docker/build-push-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + repository: terrabasedb/tdb + tags: latest diff --git a/Dockerfile b/Dockerfile index 63db7d38..95aa7263 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,6 +22,6 @@ RUN \ CMD ["tdb"] -EXPOSE 2003 +EXPOSE 2003/tcp ARG DEBIAN_FRONTEND=noninteractive diff --git a/cli/src/argparse.rs b/cli/src/argparse.rs index b3e6c4dd..c9b46dce 100644 --- a/cli/src/argparse.rs +++ b/cli/src/argparse.rs @@ -20,10 +20,24 @@ */ use crate::protocol; +use corelib::terrapipe::ADDR; +use std::env; use std::io::{self, prelude::*}; use std::process; pub async fn execute_query() { - let mut con = match protocol::Connection::new().await { + let args: Vec = env::args().skip(1).collect(); + if args.len() > 1 { + eprintln!("Incorrect number of arguments\n\tUSAGE tsh [host]"); + } + let host = match args.get(0) { + Some(h) => { + let mut addr = h.clone(); + addr.push_str(":2003"); + addr + } + None => ADDR.to_owned(), + }; + let mut con = match protocol::Connection::new(&host).await { Ok(c) => c, Err(e) => { eprintln!("ERROR: {}", e); diff --git a/cli/src/protocol/mod.rs b/cli/src/protocol/mod.rs index 438c2963..684cc49e 100644 --- a/cli/src/protocol/mod.rs +++ b/cli/src/protocol/mod.rs @@ -23,7 +23,6 @@ mod deserializer; use bytes::{Buf, BytesMut}; use corelib::builders::query::*; use corelib::de::*; -use corelib::terrapipe::*; use corelib::TResult; use deserializer::{ClientResult, Response}; use tokio::io::{AsyncReadExt, AsyncWriteExt}; @@ -34,8 +33,8 @@ pub struct Connection { } impl Connection { - pub async fn new() -> TResult { - let stream = TcpStream::connect(ADDR).await?; + pub async fn new(host: &str) -> TResult { + let stream = TcpStream::connect(host).await?; Ok(Connection { stream, buffer: BytesMut::with_capacity(BUF_CAP),