diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..2106257 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,38 @@ +# Ignore the target directory where Cargo builds your project +target + +# Ignore any files related to version control +.git +.gitignore + +# Ignore build artifacts +**/*.rs.bk + +# Ignore IDE and editor directories and files +.idea +.vscode +*.iml + +# Ignore temporary files +*.swp +*.tmp +*.temp +*.bak +*.old +*.log + +# Ignore node_modules (if you have any Node.js dependencies) +node_modules + +# Ignore Docker-related files (if you don't want them in your image) +.dockerignore +Dockerfile + +# Ignore any other local configuration files +*.local + +# Ignore any potential secrets or sensitive files +.env +*.secret +*.key +*.pem diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6fdc9cc..fa7a701 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,8 +1,12 @@ -name: CI/CD +name: CI on: - push: pull_request: + branches: + - main + push: + branches: + - main env: CARGO_TERM_COLOR: always @@ -32,4 +36,12 @@ jobs: - run: cargo build --verbose - run: cargo test --verbose - # TODO: release + build: + name: Build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: docker/build-push-action@v4 + with: + context: . + push: false diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..455b196 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,43 @@ +name: CD + +on: + push: + tags: + - '**' + +jobs: + publish: + name: "Publish Docker Image" + runs-on: ubuntu-latest + steps: + - name: Checkout Project + uses: actions/checkout@v4 + + - name: Docker Meta + id: docker_meta + uses: docker/metadata-action@v4 + with: + images: | + ghcr.io/wipacrepo/wipac-disk-tracking + tag-sha: true + tag-semver: | + {{major}} + {{major}}.{{minor}} + {{major}}.{{minor}}.{{patch}} + tags: | + type=ref,event=branch,branch=main,tag=main + type=ref,event=branch,branch=main,tag=latest + + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Publish Docker Image + uses: docker/build-push-action@v4 + with: + context: . + tags: ${{ steps.docker_meta.outputs.tags }} + labels: ${{ steps.docker_meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0f016f8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +# Dockerfile + +#---------------------------------------------------------------------------- +# Build the application +#---------------------------------------------------------------------------- +FROM rust:slim-bookworm AS build + +COPY Cargo.lock Cargo.toml /build/ +COPY src /build/src + +WORKDIR /build +RUN cargo build --release + +#---------------------------------------------------------------------------- +# Create the application image +#---------------------------------------------------------------------------- +FROM debian:bookworm-slim AS image + +COPY README.md / +COPY --from=build /build/target/release/wipac-disk-tracking /app/ + +RUN useradd -m -U app +USER app + +WORKDIR /app +CMD [ "/app/wipac-disk-tracking" ] diff --git a/bin/build-docker b/bin/build-docker new file mode 100755 index 0000000..00f227d --- /dev/null +++ b/bin/build-docker @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +# build-docker + +docker buildx build \ + --file Dockerfile \ + --tag wipac-disk-tracking:latest-SNAPSHOT \ + . diff --git a/bin/run-docker b/bin/run-docker new file mode 100755 index 0000000..8d21959 --- /dev/null +++ b/bin/run-docker @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +# run-docker + +docker run \ + --detach \ + --env=RUST_LOG=debug \ + --name=wipac_disk_tracking \ + --publish 8080:8080 \ + --rm \ + wipac-disk-tracking:latest-SNAPSHOT