Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
197 changes: 95 additions & 102 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,108 +1,101 @@
# CI for Product Catalog Service

name: product-catalog-ci

on:
pull_request:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: checkout code
uses: actions/checkout@v4

- name: Setup Go 1.22
uses: actions/setup-go@v2
with:
go-version: 1.22

- name: Build
run: |
cd src/product-catalog
go mod download
go build -o product-catalog-service main.go

- name: unit tests
run: |
cd src/product-catalog
go test ./...

code-quality:
runs-on: ubuntu-latest

steps:
- name: checkout code
uses: actions/checkout@v4

- name: Setup Go 1.22
uses: actions/setup-go@v2
with:
go-version: 1.22

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.55.2
run: golangci-lint run
working-directory: src/product-catalog

docker:
runs-on: ubuntu-latest

needs: build

steps:
- name: checkout code
uses: actions/checkout@v4

- name: Install Docker
uses: docker/setup-buildx-action@v1

- name: Login to Docker
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}

- name: Docker Push
uses: docker/build-push-action@v6
with:
context: src/product-catalog
file: src/product-catalog/Dockerfile
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/product-catalog:${{github.run_id}}


updatek8s:
runs-on: ubuntu-latest

needs: docker

steps:
- name: checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Update tag in kubernetes deployment manifest
run: |
sed -i "s|image: .*|image: ${{ secrets.DOCKER_USERNAME }}/product-catalog:${{github.run_id}}|" kubernetes/productcatalog/deploy.yaml

- name: Commit and push changes
run: |
git config --global user.email "[email protected]"
git config --global user.name "Abhishek Veeramalla"
git add kubernetes/productcatalog/deploy.yaml
git commit -m "[CI]: Update product catalog image tag"
git push origin HEAD:main -f







build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Go 1.22
uses: actions/setup-go@v2
with:
go-version: 1.22

- name: Build
run: |
cd src/product-catalog
go mod download
go build -o product-catalog-service main.go

- name: Run unit tests
run: |
cd src/product-catalog
go test ./...

code-quality:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Go 1.22
uses: actions/setup-go@v2
with:
go-version: 1.22

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.55.2
working-directory: src/product-catalog
args: run

docker:
runs-on: ubuntu-latest
needs: build

steps:
- name: Checkout code
uses: actions/checkout@v4

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

- name: Login to Docker
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}

- name: Build and Push Docker Image
uses: docker/build-push-action@v6
with:
context: src/product-catalog
file: src/product-catalog/Dockerfile
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/product-catalog:${{ github.run_id }}

update-k8s:
runs-on: ubuntu-latest
needs: docker

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Update image tag in Kubernetes deployment
run: |
sed -i "s|image: .*|image: ${{ secrets.DOCKER_USERNAME }}/product-catalog:${{ github.run_id }}|" kubernetes/productcatalog/deploy.yaml

- name: Apply Kubernetes deployment
run: |
kubectl apply -f kubernetes/productcatalog/deploy.yaml --validate=false

- name: Commit updated deployment
run: |
git config --global user.email "[email protected]"
git config --global user.name "khushboo kumari"
git add kubernetes/productcatalog/deploy.yaml
git commit -m "[CI]: Update product catalog image tag" || echo "No changes to commit"
git push origin HEAD:main -f
16 changes: 7 additions & 9 deletions kubernetes/productcatalog/deploy.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
---
# Source: opentelemetry-demo/templates/component.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: opentelemetry-demo-productcatalogservice
labels:

opentelemetry.io/name: opentelemetry-demo-productcatalogservice
app.kubernetes.io/instance: opentelemetry-demo
app.kubernetes.io/component: productcatalogservice
Expand All @@ -17,12 +14,10 @@ spec:
revisionHistoryLimit: 10
selector:
matchLabels:

opentelemetry.io/name: opentelemetry-demo-productcatalogservice
template:
metadata:
labels:

opentelemetry.io/name: opentelemetry-demo-productcatalogservice
app.kubernetes.io/instance: opentelemetry-demo
app.kubernetes.io/component: productcatalogservice
Expand All @@ -31,10 +26,9 @@ spec:
serviceAccountName: opentelemetry-demo
containers:
- name: productcatalogservice
image: abhishekf5/product-catalog:13134113508
image: in30minthing/product-catalog:${{ github.run_id }}
imagePullPolicy: IfNotPresent
ports:

- containerPort: 8080
name: service
env:
Expand All @@ -60,5 +54,9 @@ spec:
resources:
limits:
memory: 20Mi
volumeMounts:
volumes:
volumeMounts: [] # empty list to avoid syntax errors
volumes: [] # empty list to avoid syntax errors
# trigger workflow
# trigger workflow
# trigger workflow
# trigger workflow
5 changes: 0 additions & 5 deletions src/product-catalog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,3 @@ func createClient(ctx context.Context, svcAddr string) (*grpc.ClientConn, error)
grpc.WithStatsHandler(otelgrpc.NewClientHandler()),
)
}





34 changes: 32 additions & 2 deletions src/shipping/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,32 @@
target/
Dockerfile
# Include any files or directories that you don't want to be copied to your
# container here (e.g., local build artifacts, temporary files, etc.).
#
# For more help, visit the .dockerignore file reference guide at
# https://docs.docker.com/go/build-context-dockerignore/

**/.DS_Store
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/charts
**/docker-compose*
**/compose.y*ml
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/secrets.dev.yaml
**/values.dev.yaml
/bin
/target
LICENSE
README.md
8 changes: 3 additions & 5 deletions src/shipping/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ RUN if [ "${TARGETPLATFORM}" = "${BUILDPLATFORM}" ] ; then \

WORKDIR /app/

COPY /src/shipping/ /app/
COPY /pb/ /app/proto/
COPY . /app/

# Compile or crosscompile
RUN if [ "${TARGETPLATFORM}" = "${BUILDPLATFORM}" ] ; then \
Expand Down Expand Up @@ -58,8 +57,7 @@ RUN wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health
FROM debian:bookworm-slim AS release

WORKDIR /app
COPY --from=builder /app/target/release/shipping /app/shipping
COPY --from=builder /bin/grpc_health_probe /bin/grpc_health_probe
COPY . /app/

EXPOSE ${SHIPPING_PORT}
ENTRYPOINT ["/app/shipping"]
ENTRYPOINT ["/app/shipping"]
22 changes: 22 additions & 0 deletions src/shipping/README.Docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
### Building and running your application

When you're ready, start your application by running:
`docker compose up --build`.

Your application will be available at http://localhost:7077.

### Deploying your application to the cloud

First, build your image, e.g.: `docker build -t myapp .`.
If your cloud uses a different CPU architecture than your development
machine (e.g., you are on a Mac M1 and your cloud provider is amd64),
you'll want to build the image for that platform, e.g.:
`docker build --platform=linux/amd64 -t myapp .`.

Then, push it to your registry, e.g. `docker push myregistry.com/myapp`.

Consult Docker's [getting started](https://docs.docker.com/go/get-started-sharing/)
docs for more detail on building and pushing.

### References
* [Docker's Rust guide](https://docs.docker.com/language/rust/)
50 changes: 50 additions & 0 deletions src/shipping/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Comments are provided throughout this file to help you get started.
# If you need more help, visit the Docker Compose reference guide at
# https://docs.docker.com/go/compose-spec-reference/

# Here the instructions define your application as a service called "server".
# This service is built from the Dockerfile in the current directory.
# You can add other services your application may depend on here, such as a
# database or a cache. For examples, see the Awesome Compose repository:
# https://github.com/docker/awesome-compose
services:
server:
build:
context: .
target: final
ports:
- 7077:7077

# The commented out section below is an example of how to define a PostgreSQL
# database that your application can use. `depends_on` tells Docker Compose to
# start the database before your application. The `db-data` volume persists the
# database data between container restarts. The `db-password` secret is used
# to set the database password. You must create `db/password.txt` and add
# a password of your choosing to it before running `docker compose up`.
# depends_on:
# db:
# condition: service_healthy
# db:
# image: postgres
# restart: always
# user: postgres
# secrets:
# - db-password
# volumes:
# - db-data:/var/lib/postgresql/data
# environment:
# - POSTGRES_DB=example
# - POSTGRES_PASSWORD_FILE=/run/secrets/db-password
# expose:
# - 5432
# healthcheck:
# test: [ "CMD", "pg_isready" ]
# interval: 10s
# timeout: 5s
# retries: 5
# volumes:
# db-data:
# secrets:
# db-password:
# file: db/password.txt

Loading