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

Add dockerfile workflow scripts #135

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

on:
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-explorer-dapp

- 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 }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ dist-ssr
/src/config/*
!/src/config/helpers
!/src/config.devnet.ts
!/src/config.placeholder.ts
!/src/config.devnet-old.ts
!/src/config.testnet.ts
!/src/config.mainnet.ts
Expand All @@ -58,6 +59,7 @@ dist-ssr
*.sh
!prepare-free-icons.sh
!prepare-pro-icons.sh
!entrypoint.sh

# Editor directories and files
.vscode/*
Expand Down
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Use the official Node.js image
FROM node:18 AS build

# Set the working directory
WORKDIR /app

COPY . .

# Install dependencies
RUN yarn install
RUN yarn copy-placeholder-config & yarn build

# Production image
FROM nginx:alpine

# Copy the build files to the Nginx HTML directory
COPY --from=build /app/build /usr/share/nginx/html
COPY ./entrypoint.sh .
RUN chmod +x entrypoint.sh

# Expose port 80
EXPOSE 80
CMD ["./entrypoint.sh"]
18 changes: 18 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: "3.9"

services:
test:
ports:
- 127.0.0.1:80:80
container_name: explorer
build:
context: .
dockerfile: Dockerfile
environment:
START_NAME_STOP: testnet
START_CHAIN_ID_STOP: D
START_EGLD_LABEL_STOP: xEGLD
START_WALLET_ADDRESS_STOP: https://testnet-wallet.multiversx.com
START_EXPLORER_ADDRESS_STOP: https://testnet-explorer.multiversx.com
START_NFT_EXPLORER_ADDRESS_STOP: https://testnet.xspotlight.com
START_API_ADDRESS_STOP: https://testnet-api.multiversx.com
38 changes: 38 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/sh
# Replaces envs if defined
if [ -n "$START_NAME_STOP" ]; then
echo "Name defined: ${START_NAME_STOP}, replacing in config"
find /usr/share/nginx/html/ -type f -exec sed -i 's|START_NAME_STOP|'${START_NAME_STOP}'|g' {} +
fi

if [ -n "$START_CHAIN_ID_STOP" ]; then
echo "Chain ID defined: ${START_CHAIN_ID_STOP}, replacing in config"
find /usr/share/nginx/html/ -type f -exec sed -i 's|START_CHAIN_ID_STOP|'${START_CHAIN_ID_STOP}'|g' {} +
fi

if [ -n "$START_EGLD_LABEL_STOP" ]; then
echo "egldLabel defined: ${START_EGLD_LABEL_STOP}, replacing in config"
find /usr/share/nginx/html/ -type f -exec sed -i 's|START_EGLD_LABEL_STOP|'${START_EGLD_LABEL_STOP}'|g' {} +
fi

if [ -n "$START_WALLET_ADDRESS_STOP" ]; then
echo "WalletAdress defined: ${START_WALLET_ADDRESS_STOP}, replacing in config"
find /usr/share/nginx/html/ -type f -exec sed -i 's|START_WALLET_ADDRESS_STOP|'${START_WALLET_ADDRESS_STOP}'|g' {} +
fi

if [ -n "$START_EXPLORER_ADDRESS_STOP" ]; then
echo "Explorer address defined: ${START_EXPLORER_ADDRESS_STOP}, replacing in config"
find /usr/share/nginx/html/ -type f -exec sed -i 's|START_EXPLORER_ADDRESS_STOP|'${START_EXPLORER_ADDRESS_STOP}'|g' {} +
fi

if [ -n "$START_NFT_EXPLORER_ADDRESS_STOP" ]; then
echo "NFT Explorer address defined: ${START_NFT_EXPLORER_ADDRESS_STOP}, replacing in config"
find /usr/share/nginx/html/ -type f -exec sed -i 's|START_NFT_EXPLORER_ADDRESS_STOP|'${START_NFT_EXPLORER_ADDRESS_STOP}'|g' {} +
fi

if [ -n "$START_API_ADDRESS_STOP" ]; then
echo "API address defined: ${START_API_ADDRESS_STOP}, replacing in config"
find /usr/share/nginx/html/ -type f -exec sed -i 's|START_API_ADDRESS_STOP|'${START_API_ADDRESS_STOP}'|g' {} +
fi

exec nginx -g 'daemon off;'
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,19 @@
"build": "cross-env VITE_APP_CACHE_BUST=$(git rev-parse --short HEAD || echo 'local') vite build && yarn version:make",
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview",
"copy-placeholder-config": "run-script-os",
"copy-devnet-config": "run-script-os",
"copy-mainnet-config": "run-script-os",
"copy-testnet-config": "run-script-os",
"copy-multiple-config": "run-script-os",
"copy-base-interceptor": "run-script-os",
"copy-placeholder-config:nix": "cp ./src/config/config.placeholder.ts ./src/config/index.ts",
"copy-devnet-config:nix": "cp ./src/config/config.devnet.ts ./src/config/index.ts",
"copy-mainnet-config:nix": "cp ./src/config/config.mainnet.ts ./src/config/index.ts",
"copy-testnet-config:nix": "cp ./src/config/config.testnet.ts ./src/config/index.ts",
"copy-multiple-config:nix": "cp ./src/config/config.multiple.ts ./src/config/index.ts",
"copy-base-interceptor:nix": "cp ./src/interceptors/Interceptor.tsx ./src/interceptors/index.tsx",
"copy-placeholder-config:windows": "copy .\\src\\config\\config.placeholder.ts .\\src\\config\\index.ts",
"copy-devnet-config:windows": "copy .\\src\\config\\config.devnet.ts .\\src\\config\\index.ts",
"copy-mainnet-config:windows": "copy .\\src\\config\\config.mainnet.ts .\\src\\config\\index.ts",
"copy-testnet-config:windows": "copy .\\src\\config\\config.testnet.ts .\\src\\config\\index.ts",
Expand Down
Loading