Skip to content

Commit

Permalink
Publish to Docker Hub (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
lasuillard authored Sep 4, 2024
1 parent 7a4ea5d commit a396827
Show file tree
Hide file tree
Showing 13 changed files with 792 additions and 76 deletions.
16 changes: 16 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
**

# Allowed things
!src/**
!Cargo.lock
!Cargo.toml
!LICENSE

# Extra exclude from allowed things
**/*~
**/*.log
**/.DS_Store
**/Thumbs.db
**/__pycache__
**/*.md
**/*.rst
71 changes: 71 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Publish Docker image

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

permissions: read-all

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4

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

- name: Log in to the container registry
uses: docker/login-action@v3
with:
registry: ${{ vars.DOCKER_REGISTRY }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ vars.DOCKER_REGISTRY }}/${{ vars.DOCKER_REPOSITORY }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}
type=semver,pattern={{major}}.{{minor}}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

release:
runs-on: ubuntu-latest
if: startsWith(github.event.ref, 'refs/tags/v')
needs: [build-and-push-image]
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Create release
uses: softprops/action-gh-release@v2
with:
generate_release_notes: true

- name: Update Docker Hub repository description
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: ${{ vars.DOCKER_REPOSITORY }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
lcov.info
*.log
.env

# Created by https://www.toptal.com/developers/gitignore/api/osx,rust,linux,windows,visualstudiocode
# Edit at https://www.toptal.com/developers/gitignore?templates=osx,rust,linux,windows,visualstudiocode
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "onepassword-exporter"
version = "0.1.0"
version = "0.2.0"
edition = "2021"

[dependencies]
Expand Down
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM rustlang/rust:nightly-bookworm-slim AS builder

WORKDIR /build
COPY . .
RUN cargo build --release

FROM 1password/op:2 AS runtime

COPY --from=builder /build/target/release/onepassword-exporter /usr/local/bin/onepassword-exporter

ENTRYPOINT ["onepassword-exporter"]
CMD ["--host", "0.0.0.0"]
1 change: 1 addition & 0 deletions examples/grafana-dashboard/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
OP_SERVICE_ACCOUNT_TOKEN="ops_ey..."
21 changes: 21 additions & 0 deletions examples/grafana-dashboard/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Grafana Dashboard Example

This example shows example setup using Docker Compose with preconfigured Grafana dashboard for 1Password Exporter.

## Usage

Create `.env` file with appropriate values (see `.env.example` for required values):

```dotenv
OP_SERVICE_ACCOUNT_TOKEN='ops_...'
```

Start Docker Compose:

```bash
$ docker compose up -d
```

Then open Grafana running at http://localhost:3000 (default admin username and password are both `"admin"`) then go to Dashboards and you will find 1Password Exporter dashboard.

![Dashboard Screenshot](dashboard-screenshot.png)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit a396827

Please sign in to comment.