Skip to content

Commit

Permalink
chore(cyclotron): publish docker images (#24537)
Browse files Browse the repository at this point in the history
  • Loading branch information
bretthoerner authored Aug 23, 2024
1 parent e6ad4a9 commit 4a0dbb1
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 3 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/rust-cyclotron-migrator-docker.yml
Original file line number Diff line number Diff line change
@@ -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 }}
2 changes: 2 additions & 0 deletions .github/workflows/rust-docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rust-hook-migrator-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/**'
Expand Down
16 changes: 16 additions & 0 deletions rust/Dockerfile.migrate-cyclotron
Original file line number Diff line number Diff line change
@@ -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 [email protected] --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"]
2 changes: 1 addition & 1 deletion rust/Dockerfile.migrate → rust/Dockerfile.migrate-hooks
Original file line number Diff line number Diff line change
@@ -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 [email protected] --no-default-features --features native-tls,postgres --root /app/target/release/
Expand Down
2 changes: 1 addition & 1 deletion rust/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 4a0dbb1

Please sign in to comment.