Skip to content

Commit

Permalink
Add GitHub action (#1)
Browse files Browse the repository at this point in the history
* Simplify queue init

* Add docker compose file for rabbitmq dev setup

* Make queues generic

* Externalize queue payload

* Add enqueue functionallity to API

* Add dequeue functionallity to scheduler

* Remove generics for now

* Add Github Action file

* Fix matrix build paths

* Remove buggy env configuration from dockerfiles

* Revert last commit

* Add docker compose file

* Update image tags

* Update image tags

---------

Co-authored-by: Robert Jandow <[email protected]>
  • Loading branch information
Mtze and robertjndw authored Sep 22, 2023
1 parent 07d7978 commit 946342f
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 12 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Build Docker Images

on:
push:

jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- dockerfile: ./HadesAPI/Dockerfile
image: ghcr.io/mtze/hades/hades-api
- dockerfile: ./HadesScheduler/Dockerfile
image: ghcr.io/mtze/hades/hades-schduler-k8s
steps:
- name: Compute Tag
uses: actions/github-script@v6
id: compute-tag
with:
result-encoding: string
script: |
if (context.eventName === "pull_request") {
return "pr-" + context.issue.number;
}
if (context.eventName === "push") {
if (context.ref.startsWith("refs/tags/")) {
return context.ref.slice(10);
}
if (context.ref === "refs/heads/develop") {
return "develop";
}
}
return "latest";
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: all

- name: Install Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2

- name: Build and push Docker Image
uses: docker/build-push-action@v4
with:
file: ${{ matrix.dockerfile }}
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ matrix.image }}:${{ steps.compute-tag.outputs.result }}
10 changes: 4 additions & 6 deletions HadesAPI/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
# Use an official Go runtime as a parent image
FROM golang:1.21-alpine AS builder

ENV BINARY=hadesCI-API

# Set the working directory inside the container
WORKDIR /app

# Copy the Go application source code into the container
COPY . .

# Build the Go application
RUN go build -o ${BINARY} .
RUN go build -o hadesCI-api ./HadesAPI

# Start a new stage for the minimal runtime container
FROM alpine:latest
Expand All @@ -21,10 +19,10 @@ RUN apk update && apk add ca-certificates libc6-compat
WORKDIR /app

# Copy the built binary from the builder container into the minimal runtime container
COPY --from=builder /app/${BINARY} .
COPY --from=builder /app/hadesCI-api .

# Ensure the binary is executable
RUN chmod +x /app/${BINARY}
RUN chmod +x /app/hadesCI-api

# Run your Go application
CMD ["/app/${BINARY}"]
CMD ["/app/hadesCI-api"]
10 changes: 4 additions & 6 deletions HadesScheduler/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
# Use an official Go runtime as a parent image
FROM golang:1.21-alpine AS builder

ENV BINARY=hadesCI-scheduler-k8s

# Set the working directory inside the container
WORKDIR /app

# Copy the Go application source code into the container
COPY . .

# Build the Go application
RUN go build -o ${BINARY} .
RUN go build -o hadesCI-scheduler-k8s ./HadesScheduler

# Start a new stage for the minimal runtime container
FROM alpine:latest
Expand All @@ -21,10 +19,10 @@ RUN apk update && apk add ca-certificates libc6-compat
WORKDIR /app

# Copy the built binary from the builder container into the minimal runtime container
COPY --from=builder /app/${BINARY} .
COPY --from=builder /app/hadesCI-scheduler-k8s .

# Ensure the binary is executable
RUN chmod +x /app/${BINARY}
RUN chmod +x /app/hadesCI-scheduler-k8s

# Run your Go application
CMD ["/app/${BINARY}"]
CMD ["/app/hadesCI-scheduler-k8s"]
16 changes: 16 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# docker compose file for the project with three services

version: '3.7'
services:
hadesAPI:
image: hades-api
build:
context: .
dockerfile: ./HadesAPI/Dockerfile
ports:
- "8080:8080"
hadesScheduler:
image: hades-scheduler
build:
context: .
dockerfile: ./HadesScheduler/Dockerfile

0 comments on commit 946342f

Please sign in to comment.