diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..f127b09 --- /dev/null +++ b/.github/workflows/build.yml @@ -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 }} diff --git a/HadesAPI/Dockerfile b/HadesAPI/Dockerfile index 934ec20..f790c85 100644 --- a/HadesAPI/Dockerfile +++ b/HadesAPI/Dockerfile @@ -1,8 +1,6 @@ # 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 @@ -10,7 +8,7 @@ WORKDIR /app 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 @@ -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"] diff --git a/HadesScheduler/Dockerfile b/HadesScheduler/Dockerfile index 876df3b..38c7358 100644 --- a/HadesScheduler/Dockerfile +++ b/HadesScheduler/Dockerfile @@ -1,8 +1,6 @@ # 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 @@ -10,7 +8,7 @@ WORKDIR /app 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 @@ -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"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..b3a5480 --- /dev/null +++ b/docker-compose.yml @@ -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 \ No newline at end of file