sqlx icon indicating copy to clipboard operation
sqlx copied to clipboard

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

Open ansrivas opened this issue 3 years ago • 4 comments

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

ansrivas avatar Jul 30 '21 08:07 ansrivas

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 avatar Jul 30 '21 08:07 dragonnn

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.

ansrivas avatar Jul 30 '21 10:07 ansrivas

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

JSH32 avatar Jun 05 '22 21:06 JSH32

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.

oscartbeaumont avatar Jul 11 '22 14:07 oscartbeaumont

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

Owez avatar Sep 27 '22 16:09 Owez

is there a github action that does this automatically?

randomairborne avatar Oct 28 '22 01:10 randomairborne

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.

thallada avatar Oct 20 '23 05:10 thallada