Skip to content

Commit

Permalink
More CI/CD tooling
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Meade committed Jul 24, 2024
1 parent a84560b commit adca8a7
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 3 deletions.
38 changes: 38 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -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
18 changes: 15 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
name: CI/CD
name: CI

on:
push:
pull_request:
branches:
- main
push:
branches:
- main

env:
CARGO_TERM_COLOR: always
Expand Down Expand Up @@ -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
43 changes: 43 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -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 }}
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
7 changes: 7 additions & 0 deletions bin/build-docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
# build-docker

docker buildx build \
--file Dockerfile \
--tag wipac-disk-tracking:latest-SNAPSHOT \
.
10 changes: 10 additions & 0 deletions bin/run-docker
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit adca8a7

Please sign in to comment.