Skip to content

Commit

Permalink
Merge pull request #4 from helxplatform/jlp-changes
Browse files Browse the repository at this point in the history
Jlp changes
  • Loading branch information
frostyfan109 authored May 24, 2024
2 parents 5d15011 + 064ce24 commit 7270aa4
Show file tree
Hide file tree
Showing 20 changed files with 922 additions and 53 deletions.
88 changes: 88 additions & 0 deletions .github/workflows/build-push-dev-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Workflow responsible for the
# development release processes.
#

name: Build-Push-Dev-Image
on:
push:
branches:
- develop
paths-ignore:
- README.md
- .github/*
- .github/workflows/*
- LICENSE
- .gitignore
- .dockerignore
- .githooks
# Do not build another image on a pull request.
# Any push to develop will trigger a new build however.
pull_request:
branches-ignore:
- '*'
jobs:
build-push-dev-image:
runs-on: ubuntu-latest
steps:

- name: Checkout Code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
fetch-depth: 0

- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.20'

- name: Set short git commit SHA
id: vars
run: |
echo "short_sha=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_OUTPUT
# https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/

- name: Confirm git commit SHA output
run: echo ${{ steps.vars.outputs.short_sha }}

- name: Echo BINARY_NAME set in Makefile
id: BINARY_NAME
run: |
make echo >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
logout: true

- name: Login to Container Registry
uses: docker/login-action@v3
with:
registry: containers.renci.org
username: ${{ secrets.CONTAINERHUB_USERNAME }}
password: ${{ secrets.CONTAINERHUB_TOKEN }}
logout: true


# Notes on Cache:
# https://docs.docker.com/build/ci/github-actions/examples/#inline-cache
- name: Build Push Container
uses: docker/build-push-action@v5
with:
build-args: BINARY_NAME=${{ steps.BINARY_NAME.outputs.BINARY_NAME }}
context: .
push: true
# Push to renci-registry and dockerhub here.
# cache comes from dockerhub.
tags: |
${{ github.repository }}:develop
${{ github.repository }}:${{ steps.vars.outputs.short_sha }}
containers.renci.org/${{ github.repository }}:develop
containers.renci.org/${{ github.repository }}:${{ steps.vars.outputs.short_sha }}
cache-from: type=registry,ref=${{ github.repository }}:buildcache-dev
cache-to: type=registry,ref=${{ github.repository }}:buildcache-dev,mode=max
137 changes: 137 additions & 0 deletions .github/workflows/build-push-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# Workflow responsible for the
# major release processes.
#

name: Build-Push-Release
on:
push:
branches:
- master
- main
paths-ignore:
- README.md
- .old_cicd/*
- .github/*
- .github/workflows/*
- LICENSE
- .gitignore
- .dockerignore
- .githooks
tags-ignore:
- 'v[0-9]+.[0-9]+.*'
jobs:
build-push-release:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
fetch-depth: 0

- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.20'

- name: Set short git commit SHA
id: vars
run: |
echo "short_sha=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_OUTPUT
# https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/

- name: Echo BINARY_NAME set in Makefile
id: BINARY_NAME
run: |
make echo >> $GITHUB_OUTPUT
- name: Confirm git commit SHA output
run: echo ${{ steps.vars.outputs.short_sha }}

# https://github.com/marketplace/actions/git-semantic-version
- name: Semver Check
uses: paulhatch/[email protected]
id: version
with:
# The prefix to use to identify tags
tag_prefix: "v"
# A string which, if present in a git commit, indicates that a change represents a
# major (breaking) change, supports regular expressions wrapped with '/'
major_pattern: "/breaking|major/"
# A string which indicates the flags used by the `major_pattern` regular expression. Supported flags: idgs
major_regexp_flags: "ig"
# Same as above except indicating a minor change, supports regular expressions wrapped with '/'
minor_pattern: "/feat|feature|minor/"
# A string which indicates the flags used by the `minor_pattern` regular expression. Supported flags: idgs
minor_regexp_flags: "ig"
# A string to determine the format of the version output
# version_format: "${major}.${minor}.${patch}-prerelease${increment}"
version_format: "${major}.${minor}.${patch}"
search_commit_body: false

# Docker Buildx is important to caching in the Build And Push Container
# step
# https://github.com/marketplace/actions/build-and-push-docker-images
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
logout: true

- name: Login to Container Registry
uses: docker/login-action@v3
with:
registry: containers.renci.org
username: ${{ secrets.CONTAINERHUB_USERNAME }}
password: ${{ secrets.CONTAINERHUB_TOKEN }}
logout: true

# Notes on Cache:
# https://docs.docker.com/build/ci/github-actions/examples/#inline-cache
- name: Build Push Container
uses: docker/build-push-action@v5
with:
build-args: BINARY_NAME=${{ steps.BINARY_NAME.outputs.BINARY_NAME }}
push: true
# Push to renci-registry and dockerhub here.
# cache comes from dockerhub.
tags: |
containers.renci.org/${{ github.repository }}:v${{ steps.version.outputs.version }}
containers.renci.org/${{ github.repository }}:latest
containers.renci.org/${{ github.repository }}:${{ steps.vars.outputs.short_sha }}
${{ github.repository }}:v${{ steps.version.outputs.version }}
${{ github.repository }}:latest
${{ github.repository }}:${{ steps.vars.outputs.short_sha }}
cache-from: type=registry,ref=${{ github.repository }}:buildcache-release
cache-to: type=registry,ref=${{ github.repository }}:buildcache-release,mode=max

#==========================TAG & RELEASE W/ NOTES =========================

# Note: GITHUB_TOKEN is autogenerated feature of github app
# which is auto-enabled when using github actions.
# https://docs.github.com/en/actions/security-guides/automatic-token-authentication
# https://docs.github.com/en/rest/git/tags?apiVersion=2022-11-28#create-a-tag-object
# https://docs.github.com/en/rest/git/refs?apiVersion=2022-11-28#create-a-reference
# This creates a "lightweight" ref tag.
- name: Create Tag for Release
run: |
curl \
-s --fail -X POST \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/git/refs \
-d '{"ref":"refs/tags/v${{ steps.version.outputs.version }}","sha":"${{ github.sha }}"}'
# https://cli.github.com/manual/gh_release_create
- name: Create Release
env:
RELEASE_VERSION: ${{ steps.version.outputs.version }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create ${{ env.RELEASE_VERSION }} \
-t "${{ env.RELEASE_VERSION }}" \
--generate-notes \
--latest
23 changes: 23 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: build-test
on: [push]

jobs:
build-test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.20'

- name: Install dependencies
run: go get .

# Ideally we would also use golangci-lint tool
- name: Run Go fmt, vet, test
run: make test

- name: Build
run: make build
22 changes: 16 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
# Use the official Golang image to build the binary
FROM golang:1.20 AS build

ENV CGO_ENABLED 0
ARG BINARY_NAME
# Set the working directory
WORKDIR /app

# Copy the Go source files, Makefile, etc.
COPY . .

# Install make
RUN apt-get update && apt-get install -y make
# Build the Go application passing BINARY_NAME from Makefile (local development)
# or Github Action Build-Arg.
RUN go build -o ${BINARY_NAME}

# Using a multi-stage build
FROM alpine:3.18
ARG BINARY_NAME

# Use the Makefile to build the Go application
RUN make build
# Ensure we have a valid user and group
RUN addgroup -g 1000 -S assistant && \
adduser -u 1000 -G assistant -S assistant

COPY --from=build --chown=assistant:assistant /app/${BINARY_NAME} /app/
# Expose port 8080
EXPOSE 8080

WORKDIR /app

# Run the compiled binary
CMD ["/app/assistant"]
CMD ["./assistant"]
16 changes: 13 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

# Variable for the binary name
BINARY_NAME=assistant

# This is done to easily pass BINARY_NAME to github-actions
echo:
@echo "BINARY_NAME=$(BINARY_NAME)"

# Variable for the container name
REGISTRY_NAME=containers.renci.org/helxplatform
CONTAINER_NAME=gitea-assist:latest
Expand All @@ -14,17 +19,22 @@ build:
# Run tests
test:
@echo "Running tests..."
go test -v ./...
go fmt ./...
go vet ./...
go test ./...

# Build the Docker container
docker-build: build
@echo "Building Docker container..."
docker build -t $(CONTAINER_NAME) .
docker build \
--platform=linux/amd64 \
--build-arg=BINARY_NAME=$(BINARY_NAME) \
--tag=$(REGISTRY_NAME)/$(CONTAINER_NAME) \
.

# Push the Docker container
docker-push: docker-build
@echo "Pushing Docker container..."
docker tag $(CONTAINER_NAME) $(REGISTRY_NAME)/$(CONTAINER_NAME)
docker push $(REGISTRY_NAME)/$(CONTAINER_NAME)

# Clean up
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ To run the application, simply execute:
go run main.go
```

This will start an HTTP server on port 8000.
This will start an HTTP server on port 9000.

## Kubernetes Secret Creator for Gitea Credentials (mk_passwd.py)

Expand Down
4 changes: 2 additions & 2 deletions chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ spec:
livenessProbe:
httpGet:
path: /liveness
port: 8000
port: 9000
readinessProbe:
httpGet:
path: /readiness
port: 8000
port: 9000
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumeMounts:
Expand Down
2 changes: 1 addition & 1 deletion chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ securityContext: {}

service:
type: ClusterIP
port: 8000
port: 9000

ingress:
enabled: false
Expand Down
Loading

0 comments on commit 7270aa4

Please sign in to comment.