diff --git a/.github/workflows/rust-cyclotron-migrator-docker.yml b/.github/workflows/rust-cyclotron-migrator-docker.yml new file mode 100644 index 0000000000000..09384c7327a88 --- /dev/null +++ b/.github/workflows/rust-cyclotron-migrator-docker.yml @@ -0,0 +1,81 @@ +name: Build rust cyclotron-migrator docker image + +on: + workflow_dispatch: + push: + paths: + - 'rust/**' + - '.github/workflows/rust-cyclotron-migrator-docker.yml' + branches: + - 'master' + +permissions: + packages: write + +jobs: + build: + name: build and publish cyclotron-migrator image + runs-on: depot-ubuntu-22.04-4 + permissions: + id-token: write # allow issuing OIDC tokens for this workflow run + contents: read # allow reading the repo contents + packages: write # allow push to ghcr.io + + defaults: + run: + working-directory: rust + + steps: + - name: Check Out Repo + # Checkout project code + # Use sparse checkout to only select files in rust directory + # Turning off cone mode ensures that files in the project root are not included during checkout + uses: actions/checkout@v3 + with: + sparse-checkout: 'rust/' + sparse-checkout-cone-mode: false + + - name: Set up Depot CLI + uses: depot/setup-action@v1 + + - name: Login to ghcr.io + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/posthog/posthog/cyclotron-migrator + tags: | + type=ref,event=pr + type=ref,event=branch + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=sha + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v2 + + - name: Build and push migrator + id: docker_build_cyclotron_migrator + uses: depot/build-push-action@v1 + with: + context: ./rust/ + file: ./rust/Dockerfile.migrate-cyclotron + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + platforms: linux/arm64 + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Cyclotron-migrator image digest + run: echo ${{ steps.docker_build_cyclotron_migrator.outputs.digest }} diff --git a/.github/workflows/rust-docker-build.yml b/.github/workflows/rust-docker-build.yml index 95c7f3e061de2..5d636c19a8901 100644 --- a/.github/workflows/rust-docker-build.yml +++ b/.github/workflows/rust-docker-build.yml @@ -19,6 +19,8 @@ jobs: - hook-api - hook-janitor - hook-worker + - cyclotron-janitor + - cyclotron-fetch runs-on: depot-ubuntu-22.04-4 permissions: id-token: write # allow issuing OIDC tokens for this workflow run diff --git a/.github/workflows/rust-hook-migrator-docker.yml b/.github/workflows/rust-hook-migrator-docker.yml index 518374b6e241c..bc9c52a8ed339 100644 --- a/.github/workflows/rust-hook-migrator-docker.yml +++ b/.github/workflows/rust-hook-migrator-docker.yml @@ -69,7 +69,7 @@ jobs: uses: depot/build-push-action@v1 with: context: ./rust/ - file: ./rust/Dockerfile.migrate + file: ./rust/Dockerfile.migrate-hooks push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index b12b2ecdcff86..9b38709da35c3 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -34,6 +34,7 @@ jobs: - '.github/workflows/rust.yml' - '.github/workflows/rust-docker-build.yml' - '.github/workflows/rust-hook-migrator-docker.yml' + - '.github/workflows/rust-cyclotron-migrator-docker.yml' - 'posthog/management/commands/setup_test_environment.py' - 'posthog/migrations/**' - 'ee/migrations/**' diff --git a/rust/Dockerfile.migrate-cyclotron b/rust/Dockerfile.migrate-cyclotron new file mode 100644 index 0000000000000..79bab089eaeac --- /dev/null +++ b/rust/Dockerfile.migrate-cyclotron @@ -0,0 +1,16 @@ +FROM docker.io/library/rust:1.80.1-bullseye as builder + +RUN apt update && apt install build-essential cmake -y +RUN cargo install sqlx-cli@0.7.3 --no-default-features --features native-tls,postgres --root /app/target/release/ + +FROM debian:bullseye-20230320-slim AS runtime +WORKDIR /sqlx + +COPY bin /sqlx/bin/ +COPY cyclotron-core/migrations /sqlx/migrations/ + +COPY --from=builder /app/target/release/bin/sqlx /usr/local/bin + +RUN chmod +x ./bin/migrate + +CMD ["./bin/migrate"] diff --git a/rust/Dockerfile.migrate b/rust/Dockerfile.migrate-hooks similarity index 87% rename from rust/Dockerfile.migrate rename to rust/Dockerfile.migrate-hooks index e7fc120360b79..338c9b2368e22 100644 --- a/rust/Dockerfile.migrate +++ b/rust/Dockerfile.migrate-hooks @@ -1,4 +1,4 @@ -FROM docker.io/library/rust:1.74.0-buster as builder +FROM docker.io/library/rust:1.80.1-bullseye as builder RUN apt update && apt install build-essential cmake -y RUN cargo install sqlx-cli@0.7.3 --no-default-features --features native-tls,postgres --root /app/target/release/ diff --git a/rust/docker-compose.yml b/rust/docker-compose.yml index 7abfe14cae79c..10318b5beb5ef 100644 --- a/rust/docker-compose.yml +++ b/rust/docker-compose.yml @@ -70,7 +70,7 @@ services: container_name: setup-test-db build: context: . - dockerfile: Dockerfile.migrate + dockerfile: Dockerfile.migrate-hooks restart: on-failure depends_on: db: