forked from shardus/relayer-collector
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SHARD-916 Workflow addition to build and push docker image (#25)
- Loading branch information
1 parent
91afd5c
commit 1c9d78d
Showing
6 changed files
with
152 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
node_modules | ||
dist | ||
.next | ||
npm-debug.log | ||
README.md | ||
.dockerignore | ||
Dockerfile | ||
docker-compose.yml | ||
.env | ||
.github |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
name: Create and publish a Docker image | ||
|
||
on: | ||
push: | ||
branches: ['dev'] | ||
workflow_dispatch: | ||
inputs: | ||
tag: | ||
description: 'Tag for the Docker image' | ||
required: true | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }} | ||
|
||
jobs: | ||
display-image-name: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Display IMAGE_NAME | ||
run: echo "IMAGE_NAME is ${{ env.IMAGE_NAME }}" | ||
build-and-push-image: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
attestations: write | ||
id-token: write | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
- name: Log in to the Container registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Get short commit hash and determine branch name | ||
id: set-env-vars | ||
run: | | ||
# Get short commit hash | ||
echo "SHORT_COMMIT_HASH=$(git rev-parse --short HEAD)" >> $GITHUB_ENV | ||
# Determine branch name | ||
if [ "${{ github.event_name }}" == "pull_request" ]; then | ||
echo "BRANCH_NAME=${{ github.head_ref }}" >> $GITHUB_ENV # Source branch of the PR | ||
else | ||
echo "BRANCH_NAME=${{ github.ref_name }}" >> $GITHUB_ENV # Actual branch name for push events | ||
fi | ||
- name: Set Docker image tag | ||
id: set-docker-tag | ||
run: | | ||
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then | ||
echo "DOCKER_TAG=${{ github.event.inputs.tag }}" >> $GITHUB_ENV | ||
else | ||
echo "DOCKER_TAG=${{ env.BRANCH_NAME }}-${{ env.SHORT_COMMIT_HASH }}" >> $GITHUB_ENV | ||
fi | ||
- name: Build and push Docker image | ||
id: push | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: . | ||
file: Dockerfile | ||
push: true | ||
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.DOCKER_TAG }} | ||
labels: | | ||
version=${{ env.SHORT_COMMIT_HASH }} | ||
branch=${{ env.BRANCH_NAME }} | ||
- name: Generate artifact attestation | ||
uses: actions/attest-build-provenance@v1 | ||
with: | ||
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} | ||
subject-digest: ${{ steps.push.outputs.digest }} | ||
push-to-registry: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# syntax=docker/dockerfile:1 | ||
|
||
FROM node:18.16.1-alpine | ||
SHELL [ "/bin/sh", "-cex" ] | ||
|
||
# Create app directory | ||
WORKDIR /usr/src/app | ||
|
||
# Bundle app source | ||
COPY . . | ||
|
||
# Install node_modules | ||
RUN \ | ||
<<EOF | ||
npm install | ||
npm install pm2 -g | ||
EOF | ||
|
||
ENTRYPOINT [ "/usr/src/app/entrypoint.sh" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/bin/bash -x | ||
|
||
# Default number of servers to start if not set in the environment | ||
NO_OF_SERVERS=${NO_OF_SERVERS:-1} | ||
|
||
# Function to start multiple collector servers using PM2 | ||
start_collector_server() { | ||
local server_port=6001 | ||
|
||
for i in $(seq "$NO_OF_SERVERS"); do | ||
pm2 start --daemon --name "ldrpc-server-$i" npm -- run server "$server_port" | ||
server_port=$((server_port + 1)) | ||
done | ||
} | ||
|
||
# Function to start a collector using PM2 | ||
start_collector() { | ||
pm2 start --daemon --name "ldrpc-collector" npm -- run collector | ||
} | ||
|
||
# Function to start a log server using PM2 | ||
start_log_server() { | ||
pm2 start --daemon --name "ldrpc-log_server" npm -- run log_server | ||
} | ||
|
||
# Main script execution based on the input argument | ||
case "$1" in | ||
"server") | ||
start_collector_server | ||
;; | ||
"collector") | ||
start_collector | ||
;; | ||
"log_server") | ||
start_log_server | ||
;; | ||
*) | ||
echo "Error: Service '$1' is not recognizable." | ||
exit 1 | ||
;; | ||
esac | ||
|
||
# Tail PM2 logs to keep the Docker container running | ||
exec pm2 logs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters