Skip to content

Commit

Permalink
chore(logs): improve docker logs
Browse files Browse the repository at this point in the history
  • Loading branch information
developerfred committed Nov 26, 2024
1 parent f8bbcf0 commit 1f29b8f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 29 deletions.
57 changes: 31 additions & 26 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Docker CI/CD
name: Docker CI with Enhanced Checks

on:
push:
Expand All @@ -9,9 +9,10 @@ on:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
RUST_LOG: info

jobs:
build-and-test:
lint-and-test:
runs-on: ubuntu-latest
permissions:
contents: read
Expand All @@ -21,17 +22,37 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
components: rustfmt, clippy

- name: Rust cache
uses: Swatinem/rust-cache@v2

- name: Check formatting
run: cargo fmt -- --check

- name: Run clippy
run: cargo clippy -- -D warnings

- name: Run tests
run: cargo test

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to the Container registry
- name: Log in to Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
Expand All @@ -40,10 +61,8 @@ jobs:
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha
- name: Build and test Docker image
uses: docker/build-push-action@v5
with:
Expand All @@ -54,20 +73,17 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
RUST_LOG=info
target: builder
load: true

- name: Test the image
run: |
docker compose -f docker-compose.yml run test
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Build and push final multi-platform image
uses: docker/build-push-action@v5
- name: Build and push final image
if: github.event_name != 'pull_request'
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
Expand All @@ -76,16 +92,5 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max


- name: Build final image for PR
uses: docker/build-push-action@v5
if: github.event_name == 'pull_request'
with:
context: .
platforms: linux/amd64
push: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
RUST_LOG=info
22 changes: 19 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ COPY Cargo.toml Cargo.lock* ./


RUN mkdir src && \
echo "fn main() {}" > src/main.rs && \
echo "fn main() { println!(\"Initializing build...\"); }" > src/main.rs && \
cargo build --release && \
cargo build --tests && \
rm -rf src
Expand All @@ -29,7 +29,11 @@ RUN mkdir src && \
COPY src src/


RUN cargo build --release && \
ARG RUST_LOG=info
ENV RUST_LOG=${RUST_LOG}

RUN echo "Building application with RUST_LOG=${RUST_LOG}" && \
cargo build --release && \
cargo test --no-run


Expand All @@ -54,6 +58,18 @@ RUN apt-get update && \

COPY --from=builder /usr/src/app/target/release/titanium /usr/local/bin/


ENV RUST_LOG=info


COPY <<'EOF' /usr/local/bin/start.sh
#!/bin/bash
echo "Starting Titanium server with RUST_LOG=${RUST_LOG}"
exec titanium
EOF

RUN chmod +x /usr/local/bin/start.sh

EXPOSE 3000

CMD ["titanium"]
CMD ["/usr/local/bin/start.sh"]

0 comments on commit 1f29b8f

Please sign in to comment.