diff --git a/.github/workflows/push-data-observatory.yaml b/.github/workflows/push-data-observatory.yaml new file mode 100644 index 0000000000..415d90bd7c --- /dev/null +++ b/.github/workflows/push-data-observatory.yaml @@ -0,0 +1,55 @@ +name: Build and upload Data observatory container to harbor.nymte.ch +on: + workflow_dispatch: + +env: + WORKING_DIRECTORY: "nym-data-observatory" + CONTAINER_NAME: "data-observatory" + +jobs: + build-container: + runs-on: arc-ubuntu-22.04-dind + steps: + - name: Login to Harbor + uses: docker/login-action@v3 + with: + registry: harbor.nymte.ch + username: ${{ secrets.HARBOR_ROBOT_USERNAME }} + password: ${{ secrets.HARBOR_ROBOT_SECRET }} + + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Configure git identity + run: | + git config --global user.email "lawrence@nymtech.net" + git config --global user.name "Lawrence Stalder" + + - name: Get version from cargo.toml + uses: mikefarah/yq@v4.44.3 + id: get_version + with: + cmd: yq -oy '.package.version' ${{ env.WORKING_DIRECTORY }}/Cargo.toml + + - name: Check if tag exists + run: | + if git rev-parse ${{ steps.get_version.outputs.value }} >/dev/null 2>&1; then + echo "Tag ${{ steps.get_version.outputs.value }} already exists" + fi + + - name: Remove existing tag if exists + run: | + if git rev-parse ${{ env.WORKING_DIRECTORY }}-${{ steps.get_version.outputs.result }} >/dev/null 2>&1; then + git push --delete origin ${{ env.WORKING_DIRECTORY }}-${{ steps.get_version.outputs.result }} + git tag -d ${{ env.WORKING_DIRECTORY }}-${{ steps.get_version.outputs.result }} + fi + + - name: Create tag + run: | + git tag -a ${{ env.WORKING_DIRECTORY }}-${{ steps.get_version.outputs.result }} -m "Version ${{ steps.get_version.outputs.result }}" + git push origin ${{ env.WORKING_DIRECTORY }}-${{ steps.get_version.outputs.result }} + + - name: BuildAndPushImageOnHarbor + run: | + docker build -f ${{ env.WORKING_DIRECTORY }}/Dockerfile . -t harbor.nymte.ch/nym/${{ env.CONTAINER_NAME }}:${{ steps.get_version.outputs.result }} -t harbor.nymte.ch/nym/${{ env.CONTAINER_NAME }}:latest + docker push harbor.nymte.ch/nym/${{ env.CONTAINER_NAME }} --all-tags diff --git a/nym-data-observatory/Dockerfile b/nym-data-observatory/Dockerfile index bc756ebaa5..d36a910faf 100644 --- a/nym-data-observatory/Dockerfile +++ b/nym-data-observatory/Dockerfile @@ -5,6 +5,18 @@ WORKDIR /usr/src/nym/nym-data-observatory RUN cargo build --release +#------------------------------------------------------------------- +# The following environment variables are required at runtime: +# +# NYM_DATA_OBSERVATORY_CONNECTION_URL +# +# And optionally: +# +# NYM_DATA_OBSERVATORY_HTTP_PORT +# +# see https://github.com/nymtech/nym/blob/develop/nym-data-observatory/src/main.rs for details +#------------------------------------------------------------------- + FROM ubuntu:24.04 RUN apt update && apt install -yy curl ca-certificates diff --git a/nym-data-observatory/docker-compose.yml b/nym-data-observatory/docker-compose.yml index 15da0609b7..b06a988e97 100644 --- a/nym-data-observatory/docker-compose.yml +++ b/nym-data-observatory/docker-compose.yml @@ -18,8 +18,14 @@ services: dockerfile: nym-data-observatory/Dockerfile container_name: nym-data-observatory environment: - NYM_DATA_OBSERVATORY_CONNECTION_URL: "postgres://postgres:password@postgres:5432" + NYM_DATA_OBSERVATORY_CONNECTION_USERNAME: "postgres" + NYM_DATA_OBSERVATORY_CONNECTION_PASSWORD: "password" + NYM_DATA_OBSERVATORY_CONNECTION_HOST: "postgres" + NYM_DATA_OBSERVATORY_CONNECTION_PORT: "5432" + NYM_DATA_OBSERVATORY_CONNECTION_DB: "" NYM_DATA_OBSERVATORY_HTTP_PORT: 8000 + env_file: + - ../envs/qa.env volumes: pgdata: diff --git a/nym-data-observatory/src/db/mod.rs b/nym-data-observatory/src/db/mod.rs index 05c71a1728..6e8938a578 100644 --- a/nym-data-observatory/src/db/mod.rs +++ b/nym-data-observatory/src/db/mod.rs @@ -14,9 +14,7 @@ pub(crate) struct Storage { } impl Storage { - pub async fn init(connection_url: Option) -> Result { - let connection_url = - connection_url.ok_or_else(|| anyhow!("Missing the connection url for database!"))?; + pub async fn init(connection_url: String) -> Result { let connect_options = PgConnectOptions::from_str(&connection_url)?.disable_statement_logging(); diff --git a/nym-data-observatory/src/main.rs b/nym-data-observatory/src/main.rs index 4f902f4b46..da8f53d4f9 100644 --- a/nym-data-observatory/src/main.rs +++ b/nym-data-observatory/src/main.rs @@ -18,9 +18,25 @@ struct Args { #[arg(short, long, default_value = None, env = "NYM_DATA_OBSERVATORY_ENV_FILE")] env_file: Option, - /// DB connection url - #[arg(short, long, default_value = None, env = "NYM_DATA_OBSERVATORY_CONNECTION_URL")] - connection_url: Option, + /// DB connection username + #[arg(long, default_value = None, env = "NYM_DATA_OBSERVATORY_CONNECTION_USERNAME")] + connection_username: String, + + /// DB connection password + #[arg(long, default_value = None, env = "NYM_DATA_OBSERVATORY_CONNECTION_PASSWORD")] + connection_password: String, + + /// DB connection host + #[arg(long, default_value = None, env = "NYM_DATA_OBSERVATORY_CONNECTION_HOST")] + connection_host: String, + + /// DB connection port + #[arg(long, default_value = None, env = "NYM_DATA_OBSERVATORY_CONNECTION_PORT")] + connection_port: String, + + /// DB connection database name + #[arg(long, default_value = None, env = "NYM_DATA_OBSERVATORY_CONNECTION_DB")] + connection_db: String, } #[tokio::main] @@ -31,7 +47,16 @@ async fn main() -> anyhow::Result<()> { setup_env(args.env_file); // Defaults to mainnet if empty - let storage = db::Storage::init(args.connection_url).await?; + let connection_url = format!( + "postgres://{}:{}@{}:{}/{}", + args.connection_username, + args.connection_password, + args.connection_host, + args.connection_port, + args.connection_db + ); + + let storage = db::Storage::init(connection_url).await?; let db_pool = storage.pool_owned().await; tokio::spawn(async move { background_task::spawn_in_background(db_pool).await;