Skip to content

Commit

Permalink
Merge pull request #139 from chaintope/feature/nginx_image
Browse files Browse the repository at this point in the history
Upload Frontend image with nginx
  • Loading branch information
Yamaguchi committed Jul 13, 2023
2 parents b7f2fec + d424f2b commit 4f8dcb0
Show file tree
Hide file tree
Showing 16 changed files with 143 additions and 82 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/push_docker_image.yml
Expand Up @@ -38,9 +38,11 @@ jobs:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY_FRONTEND: ${{ secrets.AWS_ECR_REPO_NAME_FRONTEND }}
ECR_REPOSITORY_BACKEND: ${{ secrets.AWS_ECR_REPO_NAME_BACKEND }}
ECR_REPOSITORY_FRONTEND_NGINX: ${{ secrets.AWS_ECR_REPO_NAME_FRONTEND_NGINX }}
run: |
DOCKER_IMAGE_FRONTEND=tapyrus/explorer-frontend
DOCKER_IMAGE_BACKEND=tapyrus/explorer-backend
DOCKER_IMAGE_FRONTEND_NGINX=tapyrus/explorer-frontend-nginx
VERSION=noop
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
Expand All @@ -52,6 +54,7 @@ jobs:
fi
TAGS_FRONTEND="${DOCKER_IMAGE_FRONTEND}:${VERSION},${ECR_REGISTRY}/${ECR_REPOSITORY_FRONTEND}:${VERSION}"
TAGS_BACKEND="${DOCKER_IMAGE_BACKEND}:${VERSION},${ECR_REGISTRY}/${ECR_REPOSITORY_BACKEND}:${VERSION}"
TAGS_FRONTEND_NGINX="${DOCKER_IMAGE_FRONTEND_NGINX}:${VERSION},${ECR_REGISTRY}/${ECR_REPOSITORY_FRONTEND_NGINX}:${VERSION}"
if [[ $VERSION =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
MINOR=${VERSION%.*}
Expand All @@ -60,13 +63,17 @@ jobs:
TAGS_FRONTEND="$TAGS_FRONTEND,${ECR_REGISTRY}/${ECR_REPOSITORY_FRONTEND}:${MINOR},${ECR_REGISTRY}/${ECR_REPOSITORY_FRONTEND}:${MAJOR},${ECR_REGISTRY}/${ECR_REPOSITORY_FRONTEND}:latest"
TAGS_BACKEND="$TAGS_BACKEND,${DOCKER_IMAGE_BACKEND}:${MINOR},${DOCKER_IMAGE_BACKEND}:${MAJOR},${DOCKER_IMAGE_BACKEND}:latest"
TAGS_BACKEND="$TAGS_BACKEND,${ECR_REGISTRY}/${ECR_REPOSITORY_BACKEND}:${MINOR},${ECR_REGISTRY}/${ECR_REPOSITORY_BACKEND}:${MAJOR},${ECR_REGISTRY}/${ECR_REPOSITORY_BACKEND}:latest"
TAGS_FRONTEND_NGINX="$TAGS_FRONTEND_NGINX,${DOCKER_IMAGE_FRONTEND_NGINX}:${MINOR},${DOCKER_IMAGE_FRONTEND_NGINX}:${MAJOR},${DOCKER_IMAGE_FRONTEND_NGINX}:latest"
TAGS_FRONTEND_NGINX="$TAGS_FRONTEND_NGINX,${ECR_REGISTRY}/${ECR_REPOSITORY_FRONTEND_NGINX}:${MINOR},${ECR_REGISTRY}/${ECR_REPOSITORY_FRONTEND_NGINX}:${MAJOR},${ECR_REGISTRY}/${ECR_REPOSITORY_FRONTEND_NGINX}:latest"
elif [ "${{ github.event_name }}" = "push" ]; then
TAGS_FRONTEND="$TAGS_FRONTEND,${DOCKER_IMAGE_FRONTEND}:sha-${GITHUB_SHA::8},${ECR_REGISTRY}/${ECR_REPOSITORY_FRONTEND}:sha-${GITHUB_SHA::8}"
TAGS_BACKEND="$TAGS_BACKEND,${DOCKER_IMAGE_BACKEND}:sha-${GITHUB_SHA::8},${ECR_REGISTRY}/${ECR_REPOSITORY_BACKEND}:sha-${GITHUB_SHA::8}"
TAGS_FRONTEND_NGINX="$TAGS_FRONTEND_NGINX,${DOCKER_IMAGE_FRONTEND_NGINX}:sha-${GITHUB_SHA::8},${ECR_REGISTRY}/${ECR_REPOSITORY_FRONTEND_NGINX}:sha-${GITHUB_SHA::8}"
fi
echo ::set-output name=version::${VERSION}
echo ::set-output name=tags-frontend::${TAGS_FRONTEND}
echo ::set-output name=tags-backend::${TAGS_BACKEND}
echo ::set-output name=tags-frontend-nginx::${TAGS_FRONTEND_NGINX}
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
-
name: Set up QEMU
Expand Down Expand Up @@ -118,3 +125,23 @@ jobs:
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.licenses=${{ fromJson(steps.repo.outputs.result).license.spdx_id }}
-
name: Build and push nginx image
id: docker_build_nginx
uses: docker/build-push-action@v2
with:
context: ./nginx
file: ./nginx/Dockerfile
platforms: linux/amd64,linux/arm/v7,linux/arm64/v8
push: true
build-args: VERSION=${{ steps.prep.outputs.version }}
tags: ${{ steps.prep.outputs.tags-frontend-nginx }}
labels: |
org.opencontainers.image.title=${{ fromJson(steps.repo.outputs.result).name }}
org.opencontainers.image.description=${{ fromJson(steps.repo.outputs.result).description }}
org.opencontainers.image.url=${{ fromJson(steps.repo.outputs.result).html_url }}
org.opencontainers.image.source=${{ fromJson(steps.repo.outputs.result).clone_url }}
org.opencontainers.image.version=${{ steps.prep.outputs.version }}
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.licenses=${{ fromJson(steps.repo.outputs.result).license.spdx_id }}
41 changes: 27 additions & 14 deletions backend/libs/rest.js
@@ -1,11 +1,24 @@
const config = require('./config');
const fetch = require('node-fetch');

const http = require('node:http');
const https = require('node:https');

const httpAgent = new http.Agent({ keepAlive: true });
const httpsAgent = new https.Agent({ keepAlive: true });
const agentSelector = function (_parsedURL) {
if (_parsedURL.protocol == 'http:') {
return httpAgent;
} else {
return httpsAgent;
}
};

const baseUrl = `${config.rest.schema}://${config.rest.host}:${config.rest.port}`;
const address = {
stats: async address => {
const url = `${baseUrl}/address/${address}`;
const response = await fetch(url);
const response = await fetch(url, { agent: agentSelector });
if (response.ok) {
return response.json();
} else {
Expand All @@ -19,7 +32,7 @@ const address = {
} else {
url = `${baseUrl}/address/${address}/txs`;
}
const response = await fetch(url);
const response = await fetch(url, { agent: agentSelector });
if (response.ok) {
return response.json();
} else {
Expand All @@ -31,7 +44,7 @@ const address = {
const transaction = {
get: async txid => {
const url = `${baseUrl}/tx/${txid}`;
const response = await fetch(url);
const response = await fetch(url, { agent: agentSelector });
if (response.ok) {
return response.json();
} else if (response.status === 404) {
Expand All @@ -42,7 +55,7 @@ const transaction = {
},
raw: async txid => {
const url = `${baseUrl}/tx/${txid}/hex`;
const response = await fetch(url);
const response = await fetch(url, { agent: agentSelector });
if (response.ok) {
return response.text();
} else if (response.status === 404) {
Expand All @@ -56,7 +69,7 @@ const transaction = {
const block = {
get: async blockHash => {
const url = `${baseUrl}/block/${blockHash}`;
const response = await fetch(url);
const response = await fetch(url, { agent: agentSelector });
if (response.ok) {
return response.json();
} else if (response.status === 404) {
Expand All @@ -67,7 +80,7 @@ const block = {
},
list: async startIndex => {
const url = `${baseUrl}/blocks/${startIndex}`;
const response = await fetch(url);
const response = await fetch(url, { agent: agentSelector });
if (response.ok) {
return response.json();
} else {
Expand All @@ -76,7 +89,7 @@ const block = {
},
height: async height => {
const url = `${baseUrl}/block-height/${height}`;
const response = await fetch(url);
const response = await fetch(url, { agent: agentSelector });
if (response.ok) {
return response.text();
} else if (response.status === 404) {
Expand All @@ -87,7 +100,7 @@ const block = {
},
raw: async blockHash => {
const url = `${baseUrl}/block/${blockHash}/header`;
const response = await fetch(url);
const response = await fetch(url, { agent: agentSelector });
if (response.ok) {
return response.text();
} else if (response.status === 404) {
Expand All @@ -98,7 +111,7 @@ const block = {
},
status: async blockHash => {
const url = `${baseUrl}/block/${blockHash}/status`;
const response = await fetch(url);
const response = await fetch(url, { agent: agentSelector });
if (response.ok) {
return response.json();
} else if (response.status === 404) {
Expand All @@ -110,7 +123,7 @@ const block = {
tip: {
height: async () => {
const url = `${baseUrl}/blocks/tip/height`;
const response = await fetch(url);
const response = await fetch(url, { agent: agentSelector });
if (response.ok) {
return response.json();
} else {
Expand All @@ -125,7 +138,7 @@ const block = {
} else {
url = `${baseUrl}/block/${blockHash}/txs`;
}
const response = await fetch(url);
const response = await fetch(url, { agent: agentSelector });
if (response.ok) {
return response.json();
} else {
Expand All @@ -137,7 +150,7 @@ const block = {
const color = {
get: async colorId => {
const url = `${baseUrl}/color/${colorId}`;
const response = await fetch(url);
const response = await fetch(url, { agent: agentSelector });
if (response.ok) {
return response.json();
} else {
Expand All @@ -151,7 +164,7 @@ const color = {
} else {
url = `${baseUrl}/color/${colorId}/txs`;
}
const response = await fetch(url);
const response = await fetch(url, { agent: agentSelector });
if (response.ok) {
return response.json();
} else {
Expand All @@ -168,7 +181,7 @@ const mempool = {
} else {
url = `${baseUrl}/mempool/txs`;
}
const response = await fetch(url);
const response = await fetch(url, { agent: agentSelector });
if (response.ok) {
return {
count: response.headers.get('X-Total-Results'),
Expand Down
1 change: 1 addition & 0 deletions frontend/.gitignore
Expand Up @@ -17,6 +17,7 @@ $RECYCLE.BIN/
log.txt
npm-debug.log*

/.angular
/.idea
/.ionic
/.sass-cache
Expand Down
4 changes: 1 addition & 3 deletions frontend/angular.json
@@ -1,7 +1,6 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"defaultProject": "app",
"newProjectRoot": "projects",
"projects": {
"app": {
Expand Down Expand Up @@ -52,7 +51,6 @@
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
Expand Down Expand Up @@ -173,7 +171,7 @@
}
},
"cli": {
"defaultCollection": "@angular-eslint/schematics",
"schematicCollections": ["@angular-eslint/schematics"],
"analytics": false
},
"schematics": {
Expand Down

0 comments on commit 4f8dcb0

Please sign in to comment.