Skip to content

Commit e49b0ce

Browse files
authored
Merge pull request #75 from pauldotyu/main
feat: release workflow enhancements and version numbers in healthchecks
2 parents ef75c8c + 3fa44bd commit e49b0ce

28 files changed

+161
-18
lines changed

.github/workflows/package-ai-service.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ jobs:
5353
with:
5454
context: src/ai-service
5555
file: src/ai-service/Dockerfile
56+
platforms: linux/amd64,linux/arm64
5657
push: true
5758
tags: |
5859
${{ steps.set-variables.outputs.REPOSITORY }}/${{ steps.set-variables.outputs.IMAGE }}:latest

.github/workflows/package-makeline-service.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ jobs:
5353
with:
5454
context: src/makeline-service
5555
file: src/makeline-service/Dockerfile
56+
platforms: linux/amd64,linux/arm64
5657
push: true
5758
tags: |
5859
${{ steps.set-variables.outputs.REPOSITORY }}/${{ steps.set-variables.outputs.IMAGE }}:latest

.github/workflows/package-order-service.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ jobs:
5353
with:
5454
context: src/order-service
5555
file: src/order-service/Dockerfile
56+
platforms: linux/amd64,linux/arm64
5657
push: true
5758
tags: |
5859
${{ steps.set-variables.outputs.REPOSITORY }}/${{ steps.set-variables.outputs.IMAGE }}:latest

.github/workflows/package-product-service.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ jobs:
5353
with:
5454
context: src/product-service
5555
file: src/product-service/Dockerfile
56+
platforms: linux/amd64,linux/arm64
5657
push: true
5758
tags: |
5859
${{ steps.set-variables.outputs.REPOSITORY }}/${{ steps.set-variables.outputs.IMAGE }}:latest

.github/workflows/package-store-admin.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ jobs:
5353
with:
5454
context: src/store-admin
5555
file: src/store-admin/Dockerfile
56+
platforms: linux/amd64,linux/arm64
5657
push: true
5758
tags: |
5859
${{ steps.set-variables.outputs.REPOSITORY }}/${{ steps.set-variables.outputs.IMAGE }}:latest

.github/workflows/package-store-front.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ jobs:
5353
with:
5454
context: src/store-front
5555
file: src/store-front/Dockerfile
56+
platforms: linux/amd64,linux/arm64
5657
push: true
5758
tags: |
5859
${{ steps.set-variables.outputs.REPOSITORY }}/${{ steps.set-variables.outputs.IMAGE }}:latest

.github/workflows/package-virtual-customer.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ jobs:
5353
with:
5454
context: src/virtual-customer
5555
file: src/virtual-customer/Dockerfile
56+
platforms: linux/amd64,linux/arm64
5657
push: true
5758
tags: |
5859
${{ steps.set-variables.outputs.REPOSITORY }}/${{ steps.set-variables.outputs.IMAGE }}:latest

.github/workflows/package-virtual-worker.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ jobs:
5353
with:
5454
context: src/virtual-worker
5555
file: src/virtual-worker/Dockerfile
56+
platforms: linux/amd64,linux/arm64
5657
push: true
5758
tags: |
5859
${{ steps.set-variables.outputs.REPOSITORY }}/${{ steps.set-variables.outputs.IMAGE }}:latest
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: release-container-images
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
permissions:
8+
contents: read
9+
packages: write
10+
11+
jobs:
12+
publish-container-image:
13+
14+
runs-on: ubuntu-latest
15+
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
apps: [
20+
ai-service,
21+
makeline-service,
22+
order-service,
23+
product-service,
24+
store-admin,
25+
store-front,
26+
virtual-customer,
27+
virtual-worker
28+
]
29+
30+
steps:
31+
- name: Set environment variables
32+
id: set-variables
33+
run: |
34+
echo "REPOSITORY=ghcr.io/$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT"
35+
echo "IMAGE=${{ matrix.apps }}" >> "$GITHUB_OUTPUT"
36+
echo "VERSION=$(echo ${GITHUB_REF#refs/tags/})" >> "$GITHUB_OUTPUT"
37+
echo "CREATED=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> "$GITHUB_OUTPUT"
38+
39+
- name: Env variable output
40+
id: test-variables
41+
run: |
42+
echo ${{ steps.set-variables.outputs.REPOSITORY }}
43+
echo ${{ steps.set-variables.outputs.IMAGE }}
44+
echo ${{ steps.set-variables.outputs.VERSION }}
45+
echo ${{ steps.set-variables.outputs.CREATED }}
46+
47+
- name: Checkout code
48+
uses: actions/checkout@v2
49+
50+
- name: Set up Docker Buildx
51+
uses: docker/setup-buildx-action@v2
52+
53+
- name: Login to GitHub Container Registry
54+
uses: docker/login-action@v1
55+
with:
56+
registry: ghcr.io
57+
username: ${{ github.actor }}
58+
password: ${{ github.token }}
59+
60+
- name: Build and push
61+
uses: docker/build-push-action@v2
62+
with:
63+
context: src/${{ matrix.apps }}
64+
file: src/${{ matrix.apps }}/Dockerfile
65+
platforms: linux/amd64,linux/arm64
66+
build-args: |
67+
APP_VERSION=${{ steps.set-variables.outputs.VERSION }}
68+
push: true
69+
tags: |
70+
${{ steps.set-variables.outputs.REPOSITORY }}/${{ steps.set-variables.outputs.IMAGE }}:latest
71+
${{ steps.set-variables.outputs.REPOSITORY }}/${{ steps.set-variables.outputs.IMAGE }}:${{ steps.set-variables.outputs.VERSION }}
72+
labels: |
73+
org.opencontainers.image.source=${{ github.repositoryUrl }}
74+
org.opencontainers.image.created=${{ steps.set-variables.outputs.CREATED }}
75+
org.opencontainers.image.revision=${{ steps.set-variables.outputs.VERSION }}

src/ai-service/Dockerfile

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ FROM python:3.11.1-slim-buster
44
# Set the working directory to /app
55
WORKDIR /app
66

7+
# Set the build argument for the app version number
8+
ARG APP_VERSION=0.1.0
9+
710
# Copy the requirements file into the container
811
COPY requirements.txt .
912

@@ -16,5 +19,8 @@ COPY . .
1619
# Expose port 5001 for the FastAPI application
1720
EXPOSE 5001
1821

22+
# Set the environment variable for the app version number
23+
ENV APP_VERSION=$APP_VERSION
24+
1925
# Start the FastAPI application
2026
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "5001"]

src/ai-service/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ source .venv/bin/activate
2323
pip install -r requirements.txt
2424

2525
export USE_AZURE_OPENAI=True # set to False if you are not using Azure OpenAI
26+
export USE_AZURE_AD=False # set to True if you are using Azure OpenAI with Azure AD authentication
2627
export AZURE_OPENAI_DEPLOYMENT_NAME= # required if using Azure OpenAI
2728
export AZURE_OPENAI_ENDPOINT= # required if using Azure OpenAI
2829
export OPENAI_API_KEY= # always required

src/ai-service/main.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
from routers.description_generator import description
33
from fastapi.middleware.cors import CORSMiddleware
44
from fastapi.responses import JSONResponse
5-
import json
5+
import os
66

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

@@ -14,4 +14,4 @@ async def get_products():
1414
"""
1515
Returns status code 200
1616
"""
17-
return JSONResponse(content={"status": 'ok'}, status_code=status.HTTP_200_OK)
17+
return JSONResponse(content={"status": 'ok', "version": app.version}, status_code=status.HTTP_200_OK)

src/makeline-service/Dockerfile

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,28 @@ FROM golang:1.20.5-alpine as builder
44
# Set the working directory to /app
55
WORKDIR /app
66

7+
# Set the build argument for the app version number
8+
ARG APP_VERSION=0.1.0
9+
710
# Copy the current directory contents into the container at /app
811
COPY . /app
912

1013
# Build the Go app
11-
RUN go build -o main .
14+
RUN go build -ldflags "-X main.version=$APP_VERSION" -o main .
1215

1316
# Run the app on alpine
1417
FROM alpine:latest as runner
1518

19+
ARG APP_VERSION=0.1.0
20+
1621
# Copy the build output from the builder container
1722
COPY --from=builder /app/main .
1823

1924
# Expose port 3001 for the container
2025
EXPOSE 3001
2126

27+
# Set the environment variable for the app version number
28+
ENV APP_VERSION=$APP_VERSION
29+
2230
# Run the Go app when the container starts
2331
CMD ["./main"]

src/makeline-service/main.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,8 @@ func main() {
288288
router.PUT("/order", updateOrder)
289289
router.GET("/health", func(c *gin.Context) {
290290
c.JSON(http.StatusOK, gin.H{
291-
"status": "UP",
291+
"status": "ok",
292+
"version": os.Getenv("APP_VERSION"),
292293
})
293294
})
294295
router.Run(":3001")

src/order-service/Dockerfile

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ FROM node:18.16.0-alpine as builder
44
# Set the working directory to /app
55
WORKDIR /app
66

7+
# Set the build argument for the app version number
8+
ARG APP_VERSION=0.1.0
9+
710
# Copy package.json and package-lock.json to the container
811
COPY package*.json ./
912

@@ -16,5 +19,8 @@ COPY . .
1619
# Expose the port the app listens on
1720
EXPOSE 3000
1821

22+
# Set the environment variable for the app version number
23+
ENV APP_VERSION=$APP_VERSION
24+
1925
# Start the app
2026
CMD [ "npm", "start" ]

src/order-service/routes/root.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict'
22

3-
43
module.exports = async function (fastify, opts) {
54
fastify.post('/', async function (request, reply) {
65
const msg = request.body
@@ -9,7 +8,8 @@ module.exports = async function (fastify, opts) {
98
})
109

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

1515
fastify.get('/hugs', async function (request, reply) {

src/product-service/Dockerfile

+9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ RUN USER=root cargo new --bin product-service
55
# Create a new directory for our application
66
WORKDIR /product-service
77

8+
# Set the build argument for the app version number
9+
ARG APP_VERSION=0.1.0
10+
811
# Copy the Cargo.toml and Cargo.lock files to the container
912
COPY Cargo.toml Cargo.lock ./
1013

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

33+
# Set the build argument for the app version number
34+
ARG APP_VERSION=0.1.0
35+
3036
# Not ideal but needed to execute health checks in docker-compose
3137
RUN apt-get update && apt-get install -y wget
3238

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

42+
# Set the environment variable for the app version number
43+
ENV APP_VERSION=$APP_VERSION
44+
3645
# Run the application
3746
CMD ["./product-service"]

src/product-service/src/main.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ use std::sync::Mutex;
1010
const MAX_SIZE: usize = 262_144; // max payload size is 256k
1111

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

src/store-admin/Dockerfile

+7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# Use an official Node.js runtime as a parent image
22
FROM node:18.16.0-alpine as builder
3+
34
WORKDIR /app
45

6+
# Set the build argument for the app version number
7+
ARG APP_VERSION=0.1.0
8+
59
# Copy package.json and package-lock.json to the container
610
COPY package*.json ./
711

@@ -14,6 +18,9 @@ COPY . .
1418
# Expose the port the app listens on
1519
EXPOSE 80
1620

21+
# Set the environment variable for the app version number
22+
ENV APP_VERSION=$APP_VERSION
23+
1724
# Start the app
1825
CMD [ "npm", "run", "serve" ]
1926

src/store-admin/src/components/HealthCheck.vue

-3
This file was deleted.

src/store-admin/src/router.js

-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ import OrderDetail from "./components/OrderDetail";
44
import ProductList from "./components/ProductList";
55
import ProductDetail from "./components/ProductDetail";
66
import ProductForm from "./components/ProductForm";
7-
import HealthCheck from "./components/HealthCheck";
87

98
const routes = [
109
{ path: "/", component: OrderList },
11-
{ path: "/health", component: HealthCheck },
1210
{ path: "/orders", component: OrderList },
1311
{ path: "/order/:id", component: OrderDetail },
1412
{ path: "/products", component: ProductList },

src/store-admin/vue.config.js

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ module.exports = defineConfig({
2020

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

23+
// Health check
24+
devServer.app.get('/health', (_, res) => {
25+
const version = process.env.APP_VERSION || '0.1.0'
26+
res.send({ status: 'ok', version: version})
27+
})
28+
2329
// Get all orders
2430
devServer.app.get('/makeline/order/fetch', (_, res) => {
2531
console.log(MAKELINE_SERVICE_URL)

src/store-front/Dockerfile

+7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# Use an official Node.js runtime as a parent image
22
FROM node:18.16.0-alpine as builder
3+
34
WORKDIR /app
45

6+
# Set the build argument for the app version number
7+
ARG APP_VERSION=0.1.0
8+
59
# Copy package.json and package-lock.json to the container
610
COPY package*.json ./
711

@@ -14,6 +18,9 @@ COPY . .
1418
# Expose the port the app listens on
1519
EXPOSE 80
1620

21+
# Set the environment variable for the app version number
22+
ENV APP_VERSION=$APP_VERSION
23+
1724
# Start the app
1825
CMD [ "npm", "run", "serve" ]
1926

src/store-front/src/components/HealthCheck.vue

-3
This file was deleted.

src/store-front/src/router.js

-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ import { createWebHistory, createRouter } from "vue-router";
22
import ProductList from "./components/ProductList";
33
import ProductDetail from "./components/ProductDetail";
44
import ShoppingCart from "./components/ShoppingCart";
5-
import HealthCheck from "./components/HealthCheck";
65

76
const routes = [
87
{ path: "/", component: ProductList },
9-
{ path: "/health", component: HealthCheck },
108
{ path: "/product/:id", component: ProductDetail },
119
{ path: "/cart", component: ShoppingCart },
1210
];

0 commit comments

Comments
 (0)