Skip to content

Commit

Permalink
Merge pull request #75 from pauldotyu/main
Browse files Browse the repository at this point in the history
feat: release workflow enhancements and version numbers in healthchecks
  • Loading branch information
chzbrgr71 authored Oct 23, 2023
2 parents ef75c8c + 3fa44bd commit e49b0ce
Show file tree
Hide file tree
Showing 28 changed files with 161 additions and 18 deletions.
1 change: 1 addition & 0 deletions .github/workflows/package-ai-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
with:
context: src/ai-service
file: src/ai-service/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ steps.set-variables.outputs.REPOSITORY }}/${{ steps.set-variables.outputs.IMAGE }}:latest
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/package-makeline-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
with:
context: src/makeline-service
file: src/makeline-service/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ steps.set-variables.outputs.REPOSITORY }}/${{ steps.set-variables.outputs.IMAGE }}:latest
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/package-order-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
with:
context: src/order-service
file: src/order-service/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ steps.set-variables.outputs.REPOSITORY }}/${{ steps.set-variables.outputs.IMAGE }}:latest
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/package-product-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
with:
context: src/product-service
file: src/product-service/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ steps.set-variables.outputs.REPOSITORY }}/${{ steps.set-variables.outputs.IMAGE }}:latest
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/package-store-admin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
with:
context: src/store-admin
file: src/store-admin/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ steps.set-variables.outputs.REPOSITORY }}/${{ steps.set-variables.outputs.IMAGE }}:latest
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/package-store-front.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
with:
context: src/store-front
file: src/store-front/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ steps.set-variables.outputs.REPOSITORY }}/${{ steps.set-variables.outputs.IMAGE }}:latest
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/package-virtual-customer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
with:
context: src/virtual-customer
file: src/virtual-customer/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ steps.set-variables.outputs.REPOSITORY }}/${{ steps.set-variables.outputs.IMAGE }}:latest
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/package-virtual-worker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
with:
context: src/virtual-worker
file: src/virtual-worker/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ steps.set-variables.outputs.REPOSITORY }}/${{ steps.set-variables.outputs.IMAGE }}:latest
Expand Down
75 changes: 75 additions & 0 deletions .github/workflows/release-container-images.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: release-container-images

on:
release:
types: [published]

permissions:
contents: read
packages: write

jobs:
publish-container-image:

runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
apps: [
ai-service,
makeline-service,
order-service,
product-service,
store-admin,
store-front,
virtual-customer,
virtual-worker
]

steps:
- name: Set environment variables
id: set-variables
run: |
echo "REPOSITORY=ghcr.io/$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT"
echo "IMAGE=${{ matrix.apps }}" >> "$GITHUB_OUTPUT"
echo "VERSION=$(echo ${GITHUB_REF#refs/tags/})" >> "$GITHUB_OUTPUT"
echo "CREATED=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> "$GITHUB_OUTPUT"
- name: Env variable output
id: test-variables
run: |
echo ${{ steps.set-variables.outputs.REPOSITORY }}
echo ${{ steps.set-variables.outputs.IMAGE }}
echo ${{ steps.set-variables.outputs.VERSION }}
echo ${{ steps.set-variables.outputs.CREATED }}
- name: Checkout code
uses: actions/checkout@v2

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

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}

- name: Build and push
uses: docker/build-push-action@v2
with:
context: src/${{ matrix.apps }}
file: src/${{ matrix.apps }}/Dockerfile
platforms: linux/amd64,linux/arm64
build-args: |
APP_VERSION=${{ steps.set-variables.outputs.VERSION }}
push: true
tags: |
${{ steps.set-variables.outputs.REPOSITORY }}/${{ steps.set-variables.outputs.IMAGE }}:latest
${{ steps.set-variables.outputs.REPOSITORY }}/${{ steps.set-variables.outputs.IMAGE }}:${{ steps.set-variables.outputs.VERSION }}
labels: |
org.opencontainers.image.source=${{ github.repositoryUrl }}
org.opencontainers.image.created=${{ steps.set-variables.outputs.CREATED }}
org.opencontainers.image.revision=${{ steps.set-variables.outputs.VERSION }}
6 changes: 6 additions & 0 deletions src/ai-service/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ FROM python:3.11.1-slim-buster
# Set the working directory to /app
WORKDIR /app

# Set the build argument for the app version number
ARG APP_VERSION=0.1.0

# Copy the requirements file into the container
COPY requirements.txt .

Expand All @@ -16,5 +19,8 @@ COPY . .
# Expose port 5001 for the FastAPI application
EXPOSE 5001

# Set the environment variable for the app version number
ENV APP_VERSION=$APP_VERSION

# Start the FastAPI application
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "5001"]
1 change: 1 addition & 0 deletions src/ai-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ source .venv/bin/activate
pip install -r requirements.txt

export USE_AZURE_OPENAI=True # set to False if you are not using Azure OpenAI
export USE_AZURE_AD=False # set to True if you are using Azure OpenAI with Azure AD authentication
export AZURE_OPENAI_DEPLOYMENT_NAME= # required if using Azure OpenAI
export AZURE_OPENAI_ENDPOINT= # required if using Azure OpenAI
export OPENAI_API_KEY= # always required
Expand Down
6 changes: 3 additions & 3 deletions src/ai-service/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from routers.description_generator import description
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse
import json
import os

app = FastAPI()
app = FastAPI(version=os.environ.get("APP_VERSION", "0.1.0"))
app.include_router(description)
app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"], allow_headers=["*"])

Expand All @@ -14,4 +14,4 @@ async def get_products():
"""
Returns status code 200
"""
return JSONResponse(content={"status": 'ok'}, status_code=status.HTTP_200_OK)
return JSONResponse(content={"status": 'ok', "version": app.version}, status_code=status.HTTP_200_OK)
10 changes: 9 additions & 1 deletion src/makeline-service/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,28 @@ FROM golang:1.20.5-alpine as builder
# Set the working directory to /app
WORKDIR /app

# Set the build argument for the app version number
ARG APP_VERSION=0.1.0

# Copy the current directory contents into the container at /app
COPY . /app

# Build the Go app
RUN go build -o main .
RUN go build -ldflags "-X main.version=$APP_VERSION" -o main .

# Run the app on alpine
FROM alpine:latest as runner

ARG APP_VERSION=0.1.0

# Copy the build output from the builder container
COPY --from=builder /app/main .

# Expose port 3001 for the container
EXPOSE 3001

# Set the environment variable for the app version number
ENV APP_VERSION=$APP_VERSION

# Run the Go app when the container starts
CMD ["./main"]
3 changes: 2 additions & 1 deletion src/makeline-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ func main() {
router.PUT("/order", updateOrder)
router.GET("/health", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"status": "UP",
"status": "ok",
"version": os.Getenv("APP_VERSION"),
})
})
router.Run(":3001")
Expand Down
6 changes: 6 additions & 0 deletions src/order-service/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ FROM node:18.16.0-alpine as builder
# Set the working directory to /app
WORKDIR /app

# Set the build argument for the app version number
ARG APP_VERSION=0.1.0

# Copy package.json and package-lock.json to the container
COPY package*.json ./

Expand All @@ -16,5 +19,8 @@ COPY . .
# Expose the port the app listens on
EXPOSE 3000

# Set the environment variable for the app version number
ENV APP_VERSION=$APP_VERSION

# Start the app
CMD [ "npm", "start" ]
4 changes: 2 additions & 2 deletions src/order-service/routes/root.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict'


module.exports = async function (fastify, opts) {
fastify.post('/', async function (request, reply) {
const msg = request.body
Expand All @@ -9,7 +8,8 @@ module.exports = async function (fastify, opts) {
})

fastify.get('/health', async function (request, reply) {
return { status: 'ok' }
const appVersion = process.env.APP_VERSION || '0.1.0'
return { status: 'ok', version: appVersion }
})

fastify.get('/hugs', async function (request, reply) {
Expand Down
9 changes: 9 additions & 0 deletions src/product-service/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ RUN USER=root cargo new --bin product-service
# Create a new directory for our application
WORKDIR /product-service

# Set the build argument for the app version number
ARG APP_VERSION=0.1.0

# Copy the Cargo.toml and Cargo.lock files to the container
COPY Cargo.toml Cargo.lock ./

Expand All @@ -27,11 +30,17 @@ RUN cargo build --release
FROM debian:bullseye-slim as runner
WORKDIR /app

# Set the build argument for the app version number
ARG APP_VERSION=0.1.0

# Not ideal but needed to execute health checks in docker-compose
RUN apt-get update && apt-get install -y wget

# Copy the binary from the builder stage
COPY --from=builder /product-service/target/release/product-service /app

# Set the environment variable for the app version number
ENV APP_VERSION=$APP_VERSION

# Run the application
CMD ["./product-service"]
3 changes: 2 additions & 1 deletion src/product-service/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use std::sync::Mutex;
const MAX_SIZE: usize = 262_144; // max payload size is 256k

async fn health() -> Result<HttpResponse, Error> {
let health = json!({"status": "ok"});
let version = std::env::var("APP_VERSION").unwrap_or_else(|_| "0.1.0".to_string());
let health = json!({"status": "ok", "version": version});
Ok(HttpResponse::Ok().json(health))
}

Expand Down
7 changes: 7 additions & 0 deletions src/store-admin/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Use an official Node.js runtime as a parent image
FROM node:18.16.0-alpine as builder

WORKDIR /app

# Set the build argument for the app version number
ARG APP_VERSION=0.1.0

# Copy package.json and package-lock.json to the container
COPY package*.json ./

Expand All @@ -14,6 +18,9 @@ COPY . .
# Expose the port the app listens on
EXPOSE 80

# Set the environment variable for the app version number
ENV APP_VERSION=$APP_VERSION

# Start the app
CMD [ "npm", "run", "serve" ]

Expand Down
3 changes: 0 additions & 3 deletions src/store-admin/src/components/HealthCheck.vue

This file was deleted.

2 changes: 0 additions & 2 deletions src/store-admin/src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import OrderDetail from "./components/OrderDetail";
import ProductList from "./components/ProductList";
import ProductDetail from "./components/ProductDetail";
import ProductForm from "./components/ProductForm";
import HealthCheck from "./components/HealthCheck";

const routes = [
{ path: "/", component: OrderList },
{ path: "/health", component: HealthCheck },
{ path: "/orders", component: OrderList },
{ path: "/order/:id", component: OrderDetail },
{ path: "/products", component: ProductList },
Expand Down
6 changes: 6 additions & 0 deletions src/store-admin/vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ module.exports = defineConfig({

devServer.app.use(bodyParser.json())

// Health check
devServer.app.get('/health', (_, res) => {
const version = process.env.APP_VERSION || '0.1.0'
res.send({ status: 'ok', version: version})
})

// Get all orders
devServer.app.get('/makeline/order/fetch', (_, res) => {
console.log(MAKELINE_SERVICE_URL)
Expand Down
7 changes: 7 additions & 0 deletions src/store-front/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Use an official Node.js runtime as a parent image
FROM node:18.16.0-alpine as builder

WORKDIR /app

# Set the build argument for the app version number
ARG APP_VERSION=0.1.0

# Copy package.json and package-lock.json to the container
COPY package*.json ./

Expand All @@ -14,6 +18,9 @@ COPY . .
# Expose the port the app listens on
EXPOSE 80

# Set the environment variable for the app version number
ENV APP_VERSION=$APP_VERSION

# Start the app
CMD [ "npm", "run", "serve" ]

Expand Down
3 changes: 0 additions & 3 deletions src/store-front/src/components/HealthCheck.vue

This file was deleted.

2 changes: 0 additions & 2 deletions src/store-front/src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import { createWebHistory, createRouter } from "vue-router";
import ProductList from "./components/ProductList";
import ProductDetail from "./components/ProductDetail";
import ShoppingCart from "./components/ShoppingCart";
import HealthCheck from "./components/HealthCheck";

const routes = [
{ path: "/", component: ProductList },
{ path: "/health", component: HealthCheck },
{ path: "/product/:id", component: ProductDetail },
{ path: "/cart", component: ShoppingCart },
];
Expand Down
Loading

0 comments on commit e49b0ce

Please sign in to comment.