Skip to content

Commit

Permalink
chore(ci): add docker build and ci workflow (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
leet4tari authored Nov 22, 2024
1 parent 759516f commit 36f13d4
Show file tree
Hide file tree
Showing 11 changed files with 360 additions and 3 deletions.
10 changes: 10 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.dockerignore
Dockerfile

node_modules
npm-debug.log
.npmrc

.git
.gitignore
.github
36 changes: 36 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
name: Bug report
about: Create a report to help us improve
title: "[TITLE]"
labels: 'bug-report'
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS & Version: [e.g. iOS 10.2.1]
- Browser & Version [e.g. chrome v71.0.12345]

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser & Version [e.g. stock browser v0.1.2]

**Additional context**
Add any other context about the problem here.
27 changes: 27 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Description
---

Motivation and Context
---

How Has This Been Tested?
---

What process can a PR reviewer use to test or verify this change?
---

<!-- Checklist -->
<!-- 1. Is the title of your PR in the form that would make nice release notes? The title, excluding the conventional commit
tag, will be included exactly as is in the CHANGELOG, so please think about it carefully. -->


Breaking Changes
---

- [x] None
- [ ] Requires data directory on base node to be deleted
- [ ] Requires hard fork
- [ ] Other - Please specify

<!-- Does this include a breaking change? If so, include this line as a footer -->
<!-- BREAKING CHANGE: Description what the user should do, e.g. delete a database, resync the chain -->
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
180 changes: 180 additions & 0 deletions .github/workflows/build_docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
---
name: Build p2pool explorer docker image

'on':
push:
paths-ignore:
- '**/*.md'
tags:
- 'v[0-9]+.[0-9]+.[0-9]*'
branches:
# - 'build_dockers*'
- 'build-*'
schedule:
- cron: '05 00 * * *'
workflow_dispatch:
inputs:
version:
type: string
description: 'override image tag/version'
tag_alias:
type: string
description: 'image tag alias'

env:
DOCKER_IMAGE: p2pool-explorer
DAYS_to_EXPIRE: 30

concurrency:
# https://docs.github.com/en/actions/examples/using-concurrency-expressions-and-a-test-matrix
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
cancel-in-progress: ${{ !startsWith(github.ref, 'refs/tags/v') || github.ref != 'refs/heads/main' }}

permissions: {}

jobs:
docker_build:
name: Docker building

runs-on: ubuntu-latest

permissions:
contents: read
packages: write

strategy:
fail-fast: false
matrix:
platform: [amd64, arm64]

steps:
- name: Checkout p2pool explorer
uses: actions/checkout@v4

- name: Setup expiration for scheduled builds
if: ${{ ( github.event_name == 'schedule' && github.event.schedule == '05 00 * * *' ) || ( ! startsWith(github.ref, 'refs/tags/v') ) }}
shell: bash
run: |
echo "EXPIRATION=${{ env.DAYS_to_EXPIRE }}d" >> $GITHUB_ENV
- name: Prep docker build environment
shell: bash
run: |
ls -alht
TEBRANCH=$(git branch --show-current)
TESHA_SHORT=$(git rev-parse --short HEAD)
if [ -z "${{ inputs.version }}" ] ; then
VERSION="${TEBRANCH}_$(date -u '+%Y%m%d')_${TESHA_SHORT}"
else
VERSION=${{ inputs.version }}
fi
echo "Setting ${VERSION} as docker tag"
echo "VERSION=${VERSION}" >> $GITHUB_ENV
if [ ! -z "${{ inputs.tag_alias }}" ] ; then
echo "Setup tag_alias"
echo "TAG_ALIAS=${{ secrets.DOCKER_PROVIDER }}/${{ secrets.DOCKER_REPO }}/${{ env.DOCKER_IMAGE }}:${{ inputs.tag_alias }}" >> $GITHUB_ENV
fi
- name: Set up QEMU for Docker
uses: docker/setup-qemu-action@v3
with:
platforms: all

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE }}
${{ secrets.DOCKER_PROVIDER }}/${{ secrets.DOCKER_REPO }}/${{ env.DOCKER_IMAGE }}
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha
labels: |
maintainer=${{ github.actor }}
quay.expires-after=${{ env.EXPIRATION }}
org.opencontainers.image.vendor=TariLabs
org.opencontainers.image.title=${{ env.DOCKER_IMAGE }}
org.opencontainers.image.description=Multi-arch Docker image for ${{ env.DOCKER_IMAGE }}
org.opencontainers.image.url=https://github.com/${{ github.repository }}
org.opencontainers.image.source=https://github.com/${{ github.repository }}
flavor: |
suffix=-${{ matrix.platform }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Login to Docker Image Provider
uses: docker/login-action@v3
with:
registry: ${{ secrets.DOCKER_PROVIDER }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Docker image build and push
id: docker_build
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/${{ matrix.platform }}
push: true
provenance: false
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VERSION=${{ env.VERSION }}
tags: |
${{ steps.meta.outputs.tags }}
${{ secrets.DOCKER_PROVIDER }}/${{ secrets.DOCKER_REPO }}/${{ env.DOCKER_IMAGE }}:${{ env.VERSION }}-${{ matrix.platform }}
ghcr.io/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE }}:${{ matrix.platform }}
${{ secrets.DOCKER_PROVIDER }}/${{ secrets.DOCKER_REPO }}/${{ env.DOCKER_IMAGE }}:${{ matrix.platform }}
${{ env.TAG_ALIAS }}
outputs: |
type=registry,annotation-manifest-descriptor.org.opencontainers.image.title=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.title'] }},annotation-manifest-descriptor.org.opencontainers.image.description=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.description'] }},annotation.org.opencontainers.image.title=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.title'] }},annotation.org.opencontainers.image.description=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.description'] }},annotation-index.org.opencontainers.image.title=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.title'] }},annotation-index.org.opencontainers.image.description=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.description'] }}
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}

create-manifest:
needs: docker_build
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

steps:
- name: Log in to Registries
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login ${{ secrets.DOCKER_PROVIDER }} -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
# Create and push the multi-arch image to both registries
- name: Push multi-arch image
run: |
for registry in ghcr.io quay.io; do
if [[ "${registry}" == "ghcr.io" ]]; then
repo="${{ github.repository_owner }}"
else
repo="${{ secrets.DOCKER_REPO }}"
fi
echo "Creating multi-arch image for ${repo}/${{ env.DOCKER_IMAGE }}"
docker manifest create \
${registry}/${repo}/${{ env.DOCKER_IMAGE }}:latest \
${registry}/${repo}/${{ env.DOCKER_IMAGE }}:amd64 \
${registry}/${repo}/${{ env.DOCKER_IMAGE }}:arm64
echo "Inspect multi-arch image for ${repo}/${{ env.DOCKER_IMAGE }}"
docker manifest inspect --verbose ${registry}/${repo}/${{ env.DOCKER_IMAGE }}:latest
echo "Pusing multi-arch image for ${repo}/${{ env.DOCKER_IMAGE }}"
docker manifest push ${registry}/${repo}/${{ env.DOCKER_IMAGE }}:latest || true
done
24 changes: 24 additions & 0 deletions .github/workflows/pr_signed_commits_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
# Checks if the comments are signed or not
name: PR - Signed commits check

'on':
pull_request_target

concurrency:
# https://docs.github.com/en/actions/examples/using-concurrency-expressions-and-a-test-matrix
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
cancel-in-progress: ${{ !startsWith(github.ref, 'refs/tags/v') || github.ref != 'refs/heads/main' }}

permissions: {}

jobs:
check-signed-commits:
name: Check signed commits in PR
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Check signed commits in PR
uses: 1Password/check-signed-commits-action@v1
30 changes: 30 additions & 0 deletions .github/workflows/pr_title.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
# Checks that PR titles conform to Conventional Commits
# See https://www.conventionalcommits.org/en/v1.0.0/ for more information
name: PR

'on':
pull_request:
types:
- opened
- reopened
- edited
- synchronize

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
check-title:
runs-on: ubuntu-latest
steps:
- name: install
run: |
npm install -g @commitlint/cli @commitlint/config-conventional
echo "module.exports = {extends: ['@commitlint/config-conventional']}" > commitlint.config.js
- name: lint
run: |
echo "$PR_TITLE" | commitlint
env:
PR_TITLE: ${{github.event.pull_request.title}}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,7 @@ dist
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
.pnp.*

# OSX files
.DS_Store
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# syntax = docker/dockerfile:1.3

# https://hub.docker.com/_/node
ARG NODE_VERSION=23-bullseye-slim

FROM node:$NODE_VERSION

RUN apt-get update && \
apt-get install -y --no-install-recommends dumb-init

ENV NODE_ENV production
WORKDIR /usr/src/app
COPY --chown=node:node . .
RUN npm install
#RUN npm install debug

ENV P2POOL_URL=${P2POOL_URL:-http://127.0.0.1:19000}

EXPOSE 3000

USER node
CMD ["dumb-init", "node", "server.js"]
16 changes: 16 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
version: '3.7'
services:
p2pool-explorer:
container_name: p2pool-explorer
image: quay.io/tarilabs/p2pool-explorer
restart: unless-stopped
ports:
- "3000:3000"
environment:
- P2POOL_URL=http://p2pool-node:19000

p2pool-node:
container_name: p2pool-node
image: quay.io/tarilabs/sha-p2pool:v0.9.2
restart: unless-stopped
5 changes: 3 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ const axios = require('axios');
const path = require('path');

const app = express();
const PORT = 3000;
const PORT = process.env.PORT || 3000;

const P2POOL_URL = process.env.P2POOL_URL || "http://127.0.0.1:19000";

const P2POOL_URL = "http://127.0.0.1:19000";
// Set EJS as the templating engine
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views'));
Expand Down

0 comments on commit 36f13d4

Please sign in to comment.