Skip to content

Commit

Permalink
Merge pull request #24 from hxckr-org/add-migrations-for-local-dev-an…
Browse files Browse the repository at this point in the history
…d-production

feat: add migrations for local dev and production
  • Loading branch information
daviroo authored Oct 3, 2024
2 parents fd6646b + 7f72b4c commit 19e37d5
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
29 changes: 27 additions & 2 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,40 @@ jobs:
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ env.DOCKERHUB_TOKEN }}

- name: Build and push Docker image
- name: Build and push Docker image (Development)
if: github.event_name == 'push'
uses: docker/build-push-action@v4
with:
context: .
file: Dockerfile.dev
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ env.IMAGE_NAME }}:latest
${{ env.IMAGE_NAME }}:dev
${{ env.IMAGE_NAME }}:${{ github.sha }}
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache
cache-to: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache,mode=max

- name: Build and push Docker image (Production)
if: github.event_name == 'release'
uses: docker/build-push-action@v4
with:
context: .
file: Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ env.IMAGE_NAME }}:latest
${{ env.IMAGE_NAME }}:${{ github.ref_name }}
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache
cache-to: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache,mode=max

- name: Run migrations (Production)
if: github.event_name == 'release'
env:
DATABASE_URL: ${{ secrets.PRODUCTION_DATABASE_URL }}
run: |
docker run --rm \
-e DATABASE_URL \
${{ env.IMAGE_NAME }}:${{ github.ref_name }} \
diesel migration run
18 changes: 18 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Build stage
FROM rust:latest as builder
WORKDIR /usr/src/hxckr-core
COPY . .
RUN apt-get update && apt-get install -y libpq-dev
RUN cargo install diesel_cli --no-default-features --features postgres
RUN cargo build --release

# Runtime stage
FROM debian:bookworm-slim
RUN apt-get update && apt-get install -y libpq-dev && rm -rf /var/lib/apt/lists/*
COPY --from=builder /usr/src/hxckr-core/target/release/hxckr-core /usr/local/bin/hxckr-core
COPY --from=builder /usr/local/cargo/bin/diesel /usr/local/bin/diesel
COPY --from=builder /usr/src/hxckr-core/migrations /migrations
COPY entrypoint.dev.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
8 changes: 8 additions & 0 deletions entrypoint.dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
set -e

echo "Running database migrations..."
diesel migration run

echo "Starting hxckr-core..."
exec hxckr-core

0 comments on commit 19e37d5

Please sign in to comment.