Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adding docker image support with docker publish Github_action #58

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/workflows/docker_publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Publishing Docker image

on:
push:
branches: [ "main" ]
paths-ignore:
- 'README.md'
- '**/*_test.go'
pull_request:
branches: [ "main" ]
paths-ignore:
- 'README.md'
- '**/*_test.go'

jobs:
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v4

- name: Log in to Harbor
uses: docker/login-action@v3
with:
registry: demo.goharbor.io
username: ${{ secrets.REGISTRY_GOHARBOR_USERNAME }}
password: ${{ secrets.REGISTRY_GOHARBOR_PASSWORD }}

- name: Install Cosign
uses: sigstore/cosign-installer@v3.1.1

- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile
tags: demo.goharbor.io/library/harbor-cli:0.0.1
push: true
labels: ${{ steps.meta.outputs.labels }}

- name: Get the image digest
id: image_digest
run: |
echo "IMAGE_DIGEST=$(docker inspect --format='{{index .RepoDigests 0}}' demo.goharbor.io/library/harbor-cli:1.2.5)" >> $GITHUB_ENV

- name: Sign image with a key
run: |
cosign sign --yes --key env://COSIGN_PRIVATE_KEY ${{ env.IMAGE_DIGEST }}
env:
COSIGN_PRIVATE_KEY: ${{ secrets.COSIGN_PRIVATE_KEY }}
COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }}
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Stage 1: Build the Go binary
FROM golang:1.21-alpine AS builder

WORKDIR /app

COPY go.mod go.sum ./

# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed
RUN go mod download

COPY . .

RUN go build -o harbor ./cmd/harbor

# Stage 2: Create a small image for the Go binary
FROM alpine:latest

WORKDIR /root/

# Copy the Pre-built binary file from the previous stage
COPY --from=builder /app/harbor .

CMD ["./harbor"]