Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added dockerfile, workflow and entrypoint #1364

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
45 changes: 45 additions & 0 deletions .github/workflows/build-docker-image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Publish Docker image

on:
release:
types: [published]
workflow_dispatch:

jobs:
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
attestations: write
steps:
- name: Check out the repo
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '18' # Specify your Node.js version

- name: Log in to Docker Hub
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: multiversx/mx-api-service

- name: Build and push Docker image
id: push
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM node:18.19-alpine

WORKDIR /app
RUN chown -R node:node /app

USER node
RUN mkdir -p /app/dist/src
COPY --chown=node . /app

RUN npm install
RUN npm run init
RUN npm run build

EXPOSE 3001
RUN chmod +x entrypoint.sh

CMD ["./entrypoint.sh"]
46 changes: 46 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/sh
# ENV VARIABLES
# MVX_ENV - defines what config to copy (default devnet)
# ELASTICSEARCH_URL - defines custom elasticsearch url - eg https://devnet-index.multiversx.com
# GATEWAY_URL - defines custom gateway url - eg https://devnet-gateway.multiversx.com
# REDIS_IP - defines redis ip - default 127.0.0.1

# CHECK IF ENV IS DEFINED
if [ -n "$MVX_ENV" ] && [ "$MVX_ENV" = "devnet" ]; then
# Copy config file
cp ./config/config.${MVX_ENV}.yaml /app/dist/config/config.yaml

if [ $? -eq 0 ]; then
echo "Config file copied successfully from config/config.${MVX_ENV}.yaml /app/dist/config/config.yaml"
else
echo "Failed to copy the file."
fi

else
cp ./config/config.devnet.yaml /app/dist/config/config.yaml

if [ $? -eq 0 ]; then
echo "Default config file copied successfully from config/config.devnet.yaml /app/dist/config/config.yaml"
else
echo "Failed to copy the file."
fi
fi

# Replaces urls if defined
if [ -n "$REDIS_IP" ]; then
echo "Redis IP defined: ${REDIS_IP}, replacing in config"
sed -i "s|redis: '127.0.0.1'|redis: '${REDIS_IP}'|g" /app/dist/config/config.yaml
fi

if [ -n "$ELASTICSEARCH_URL" ]; then
echo "Elasticsearch url defined: ${ELASTICSEARCH_URL}, replacing in config"
sed -i "/^ elastic:/!b; n; s|.*| - '${ELASTICSEARCH_URL}'|" /app/dist/config/config.yaml
fi

if [ -n "$GATEWAY_URL" ]; then
echo "Gateway url defined: ${GATEWAY_URL}, replacing in config"
sed -i "/^ gateway:/!b; n; s|.*| - '${GATEWAY_URL}'|" /app/dist/config/config.yaml
fi


exec /usr/local/bin/node dist/src/main.js
Loading