launchbadge / sqlx

🧰 The Rust SQL Toolkit. An async, pure Rust SQL crate featuring compile-time checked queries without a DSL. Supports PostgreSQL, MySQL, and SQLite.
Apache License 2.0
13.31k stars 1.26k forks source link

RFC: Would it make sense to release binaries of sqlx-cli? #1353

Open ansrivas opened 3 years ago

ansrivas commented 3 years ago

Hi, I was wondering if it would make sense to release the binary of sqlx-cli probably statically compiled?

The use case is to simply wrap it up in a docker-container and use it for migrations. The motivation here is, this just makes it very easy to fetch the binary and use it as it is.

I did something similar in my fork here - https://github.com/ansrivas/sqlx/releases/tag/v0.5.5

FROM ubuntu:20.04 as builder

RUN apt-get update -y && apt install wget -y --no-install-recommends
RUN wget https://github.com/ansrivas/sqlx/releases/download/v0.5.5/sqlx && chmod +x sqlx
COPY migrations /opt/src/migrations

FROM gcr.io/distroless/base
COPY --from=builder /opt/src/sqlx /usr/local/bin/sqlx
COPY --from=builder /opt/src/migrations /opt/src/migrations
WORKDIR /opt/src
CMD ["sqlx", "migrate", "run"]

NOTE: In case others are following different methods to run migrations, please feel free to recommend here. Thanks

dragonnn commented 3 years ago

NOTE: In case others are following different methods to run migrations, please feel free to recommend here.

You know you can embedded migrations with sqlx::migrate!("./migrations") within you program binary? That's the best way to do it in my opinion and deploy, since you don't even need to push the migrations files into the container.

ansrivas commented 3 years ago

NOTE: In case others are following different methods to run migrations, please feel free to recommend here.

You know you can embedded migrations with sqlx::migrate!("./migrations") within you program binary? That's the best way to do it in my opinion and deploy, since you don't even need to push the migrations files into the container.

@dragonnn oh thanks, I didn't know this. In fact, this solves this completely.

JSH32 commented 2 years ago

Some people use kube and would like to run migrations on deploy using init or helm charts so this would be useful.

oscartbeaumont commented 2 years ago

Being able to download a pre-compiled binary would be way faster in CI workflows such as GitHub Actions. Currently, it takes around 4m 30sec to install the CLI while downloading a binary would be a matter of seconds.

Owez commented 2 years ago

I'd like binaries, building sqlx-cli takes up a decent chunk of my runner's time.

randomairborne commented 1 year ago

is there a github action that does this automatically?

thallada commented 1 year ago

is there a github action that does this automatically?

Not to my knowledge, but you can cache the ~/.cargo/bin folder in between workflow runs so it doesn't need to install after the first build, e.g.:

    - name: Cache Cargo binaries 
       uses: actions/cache@v3 
       with: 
         path: ~/.cargo/bin 
         key: ${{ runner.os }}-cargo-bin
...
    - name: Install sqlx-cli 
       run: cargo install sqlx-cli --no-default-features --features native-tls,postgres

cargo install will skip installing if the latest version is already in the cache-restored ~/.cargo/bin.