Skip to content

Commit

Permalink
feat(ci): enhance docker build and push workflow to support multiple …
Browse files Browse the repository at this point in the history
…images and repositories
  • Loading branch information
ozeliurs committed Oct 7, 2024
1 parent 876c47d commit 5b95242
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 15 deletions.
44 changes: 40 additions & 4 deletions .github/workflows/docker-build-push.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
name: Build and Push Base Docker Image
name: Build and Push Docker Images

on:
push:
paths:
- "build-base/Dockerfile"
- "build-base/**"
- "api/**"
- "solver/**"
workflow_dispatch:

permissions:
contents: read
packages: write

jobs:
build-and-push:
build-and-push-base:
if: github.event_name == 'workflow_dispatch' || contains(github.event.push.paths, 'build-base/')
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand All @@ -30,11 +33,44 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
- name: Build and push base image
uses: docker/build-push-action@v2
with:
context: ./build-base
file: ./build-base/Dockerfile
push: true
tags: ghcr.io/${{ env.REPO_LOWERCASE }}/base:latest
platforms: linux/amd64,linux/arm64

build-and-push-grpc-server:
needs: build-and-push-base
if: |
always() &&
(needs.build-and-push-base.result == 'success' || needs.build-and-push-base.result == 'skipped') &&
(github.event_name == 'workflow_dispatch' || contains(github.event.push.paths, 'build-base/') || contains(github.event.push.paths, 'api/') || contains(github.event.push.paths, 'solver/'))
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set lowercase repository name
run: echo "REPO_LOWERCASE=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV

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

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

- name: Build and push grpc-server image
uses: docker/build-push-action@v2
with:
context: .
file: ./api/Dockerfile
push: true
tags: ghcr.io/${{ env.REPO_LOWERCASE }}/grpc-server:latest
platforms: linux/amd64,linux/arm64
5 changes: 3 additions & 2 deletions api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM apoorvapewpew/eternity2-dependencies:latest as builder
# FROM apoorvapewpew/eternity2-dependencies:latest as builder
FROM ghcr.io/startupnationlabs/eternity2/base:latest as builder

# Copy
WORKDIR /app
Expand All @@ -21,4 +22,4 @@ EXPOSE 50051
LABEL project="eternity2"
LABEL description="Eternity II Asio gRPC server"
LABEL version="1.0"
LABEL repository="https://github.com/Apoorva64/eternity2"
LABEL repository="https://github.com/Apoorva64/eternity2"
25 changes: 16 additions & 9 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
services:
grpc-server:
image: ghcr.io/apoorva64/eternity2/api:latest
ports:
- "50051:50051"
build:
context: .
dockerfile: api/Dockerfile
container_name: grpc-server
image: ghcr.io/startupnationlabs/eternity2/grpc-server:latest
networks:
- eternity2

envoy:
image: ghcr.io/apoorva64/eternity2/envoy:latest
image: ghcr.io/startupnationlabs/eternity2/envoy:latest
environment:
- SOLVER_API=grpc-server
build:
context: envoy
ports:
- "50052:50052"
networks:
- eternity2

frontend:
container_name: frontend
image: ghcr.io/startupnationlabs/eternity2/frontend:latest
ports:
- "80:80"

networks:
eternity2:

0 comments on commit 5b95242

Please sign in to comment.