Skip to content

Commit

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

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

jobs:
lint-and-test:
build-and-test:
runs-on: ubuntu-latest
permissions:
contents: read
Expand All @@ -22,37 +21,17 @@ 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 Registry
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract Docker metadata
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
Expand All @@ -61,8 +40,10 @@ 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 @@ -73,17 +54,20 @@ 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 image
if: github.event_name != 'pull_request'
- name: Build and push final multi-platform image
uses: docker/build-push-action@v5
if: github.event_name != 'pull_request'
with:
context: .
platforms: linux/amd64,linux/arm64
Expand All @@ -92,5 +76,16 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
RUST_LOG=info


- 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
108 changes: 108 additions & 0 deletions .github/workflows/ghcr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: Container Registry Deploy

on:
push:
branches: ["main"]
tags: ["v*"]
pull_request:
branches: ["main"]

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
CARGO_TERM_COLOR: always
RUST_LOG: info

permissions:
contents: read
packages: write

jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
pkg-config \
libgtk-3-dev \
libwebkit2gtk-4.0-dev \
libayatana-appindicator3-dev \
librsvg2-dev \
libgdk3.0-cil \
libgdk-pixbuf2.0-dev \
libglib2.0-dev \
cmake \
libxdo-dev \
libssl-dev
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt, clippy

- name: Rust cache
uses: Swatinem/rust-cache@v2
with:
shared-key: "rust-cache"

- name: Run tests
run: cargo test

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

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

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

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

- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha
- name: Build and test
uses: docker/build-push-action@v5
with:
context: .
load: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:test
cache-from: type=gha
cache-to: type=gha,mode=max
target: builder

- name: Test the container
run: |
docker compose -f docker-compose.yml run test
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
62 changes: 34 additions & 28 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ FROM rustlang/rust:nightly AS builder

RUN apt-get update && \
apt-get install -y \
pkg-config \
libssl-dev \
libgtk-3-dev \
libwebkit2gtk-4.0-dev \
libayatana-appindicator3-dev \
librsvg2-dev \
cmake \
libxdo-dev && \
rm -rf /var/lib/apt/lists/*
pkg-config \
libgtk-3-dev \
libwebkit2gtk-4.0-dev \
libayatana-appindicator3-dev \
librsvg2-dev \
libgdk3.0-cil \
libgdk-pixbuf2.0-dev \
libglib2.0-dev \
cmake \
libxdo-dev \
libssl-dev \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /usr/src/app

Expand All @@ -27,33 +30,34 @@ RUN mkdir src && \


COPY src src/
COPY rust-toolchain.toml .


ARG RUST_LOG=info
ENV RUST_LOG=${RUST_LOG}

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


FROM debian:bookworm-slim


RUN apt-get update && \
apt-get install -y \
ca-certificates \
libwebkit2gtk-4.0-37 \
libjavascriptcoregtk-4.0-18 \
libsoup2.4-1 \
gstreamer1.0-plugins-base \
gstreamer1.0-plugins-good \
gstreamer1.0-x \
libgtk-3-0 \
curl \
librsvg2-2 \
libxdo3 && \
rm -rf /var/lib/apt/lists/*
ca-certificates \
libgtk-3-0 \
libwebkit2gtk-4.0-37 \
libayatana-appindicator3-1 \
librsvg2-2 \
gstreamer1.0-plugins-base \
gstreamer1.0-plugins-good \
gstreamer1.0-x \
libgdk3.0-cil \
libgdk-pixbuf2.0-0 \
curl \
libxdo3 \
&& rm -rf /var/lib/apt/lists/*


COPY --from=builder /usr/src/app/target/release/titanium /usr/local/bin/
Expand All @@ -62,14 +66,16 @@ COPY --from=builder /usr/src/app/target/release/titanium /usr/local/bin/
ENV RUST_LOG=info


COPY <<'EOF' /usr/local/bin/start.sh
COPY <<'EOF' /usr/local/bin/healthcheck.sh
#!/bin/bash
echo "Starting Titanium server with RUST_LOG=${RUST_LOG}"
exec titanium
curl -f http://localhost:3000/health || exit 1
EOF

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

HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD ["/usr/local/bin/healthcheck.sh"]

EXPOSE 3000

CMD ["/usr/local/bin/start.sh"]
CMD ["titanium"]
9 changes: 7 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
services:
app:
build: .
image: ${REGISTRY:-ghcr.io}/${IMAGE_NAME:developerfred/titanium}:${TAG:-latest}
build:
context: .
args:
RUST_LOG: ${RUST_LOG:-info}
ports:
- "3000:3000"
environment:
- RUST_LOG=info
- RUST_LOG=${RUST_LOG:-info}
- RUST_BACKTRACE=1
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
interval: 30s
Expand Down

0 comments on commit fd3f4a9

Please sign in to comment.