Skip to content

Commit

Permalink
chore: Added docker publishing for git service (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
daviroo authored Sep 11, 2024
1 parent 85b3819 commit dd8ac59
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 2 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Docker Publish

on:
push:
branches: [ "main" ]
release:
types: [created]

env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/hxckr-git-service

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

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
install: true

- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ env.DOCKERHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: ./git-service
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ env.IMAGE_NAME }}:latest
${{ env.IMAGE_NAME }}:${{ github.sha }}
${{ env.IMAGE_NAME }}:${{ github.ref_name }}
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache
cache-to: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache,mode=max
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Hxckr Infra Repo
# HXCKR Infrastructure

> This repo contains service to run the infrasturacture for the hxckr project which include:
This repository contains the infrastructure code for the HXCKR project.

## Components

- [Git Service](./git-service/README.md): A web service that interacts with Soft Serve git server, allowing for Soft Serve commands to be accessible over HTTP.

1. Service for interacting with the soft serve git server(please to [Git Service Setup](./git-service/SETUP.md))
33 changes: 33 additions & 0 deletions git-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Use the official Rust image as the base image
FROM rust:1.76 as builder

# Create a new empty shell project
RUN USER=root cargo new --bin git-service
WORKDIR /git-service

# Copy our manifests
COPY ./Cargo.lock ./Cargo.lock
COPY ./Cargo.toml ./Cargo.toml

# Build only the dependencies to cache them
RUN cargo build --release
RUN rm src/*.rs

# Copy the source code
COPY ./src ./src

# Build for release
RUN rm ./target/release/deps/git_service*
RUN cargo build --release

# Final stage
FROM debian:bullseye-slim

# Install OpenSSL and ca-certificates
RUN apt-get update && apt-get install -y openssl ca-certificates && rm -rf /var/lib/apt/lists/*

# Copy the build artifact from the builder stage
COPY --from=builder /git-service/target/release/git-service .

# Set the startup command
CMD ["./git-service"]
32 changes: 32 additions & 0 deletions git-service/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Git Service

The Git Service is a web service that interacts with a Soft Serve git server, providing HTTP endpoints to perform various git-related operations.

## What the service does

This service acts as a bridge between HTTP clients and a Soft Serve git server. It provides the following functionalities:

1. Create repositories: Allows clients to create new git repositories on the Soft Serve server.
2. Generate authentication tokens: Creates and returns authentication tokens for accessing repositories.
3. Return authenticated URLs: Provides URLs with built-in authentication tokens for easy access to repositories.

The service essentially wraps Soft Serve's SSH-based commands into HTTP endpoints, making it easier to integrate git operations into web applications or other services that prefer HTTP interactions.

## How it is published

The Git Service is containerized using Docker and published using GitHub Actions. Here's an overview of the process:

1. Dockerfile: The service uses a multi-stage Dockerfile to build the Rust application and create a lean runtime image.

2. GitHub Actions: A workflow (`.github/workflows/docker-publish.yml`) is set up to automatically build and publish the Docker image when changes are pushed to the main branch or a new release is created.

3. Multi-platform support: The Docker image is built for both `linux/amd64` and `linux/arm64` platforms.

4. DockerHub: The built images are pushed to DockerHub under the repository `${DOCKERHUB_USERNAME}/hxckr-git-service`.

5. Tagging: Each image is tagged with:
- `latest`: Always points to the most recent build
- The git commit SHA
- The git reference name (branch or tag)

To use the published Docker image, you can pull it from DockerHub:

0 comments on commit dd8ac59

Please sign in to comment.