Skip to content

Commit

Permalink
Frontier Chain Init
Browse files Browse the repository at this point in the history
  • Loading branch information
philiparthurmoore committed Apr 11, 2021
0 parents commit e5945d2
Show file tree
Hide file tree
Showing 32 changed files with 14,033 additions and 0 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# This is a basic workflow that is manually triggered

name: frontierchain

# Controls when the action will run. Workflow runs when manually triggered using the UI
# or API.
on: [push, pull_request]

# This workflow makes x86_64 binaries for mac, windows, and linux.

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
arch: [amd64, arm64]
targetos: [windows, darwin, linux]
name: frontierchain ${{ matrix.arch }} for ${{ matrix.targetos }}
steps:
- uses: actions/checkout@v2
- name: Setup go
uses: actions/setup-go@v1
with:
go-version: 1.15
env:
GOOS: ${{ matrix.targetos }}
GOARCH: ${{ matrix.arch }}

- name: Compile
run: |
go mod download
cd cmd/frontierchaind
go build .
cd ..
cd frontierchaincli
go build .
- uses: actions/upload-artifact@v2
with:
name: frontierchaincli ${{ matrix.targetos }} ${{ matrix.arch }}
path: cmd/frontierchaincli/frontierchaincli

- uses: actions/upload-artifact@v2
with:
name: frontierchaind ${{ matrix.targetos }} ${{ matrix.arch }}
path: cmd/frontierchaind/frontierchaind

31 changes: 31 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Docker
on: []

jobs:
amd64:
name: frontierchain Docker
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2

- name: Set up QEMU
run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes --credential yes

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
with:
version: latest

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
run: docker buildx build --tag ${{ secrets.DOCKERHUB_USERNAME }}/frontierchain --file Dockerfile --platform linux/amd64,linux/arm64 --cache-from ${{ secrets.DOCKERHUB_USERNAME }}/frontierchain:cache --cache-to ${{ secrets.DOCKERHUB_USERNAME }}/frontierchain:cache --push --progress tty .

- name: Build and push UI
run: docker buildx build --tag ${{ secrets.DOCKERHUB_USERNAME }}/frontierchain-ui --file vue/Dockerfile --platform linux/amd64,linux/arm64 --cache-from ${{ secrets.DOCKERHUB_USERNAME }}/frontierchain-ui:cache --cache-to ${{ secrets.DOCKERHUB_USERNAME }}/frontierchain-ui:cache --push --progress tty ./vue
24 changes: 24 additions & 0 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Build and Deploy
on: []
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v2.3.1 # If you're using actions/checkout@v2 you must set persist-credentials to false in most cases for the deployment to work correctly.
with:
persist-credentials: false

- name: Install and Build 🔧 # This example project is built using npm and outputs the result to the 'build' folder. Replace with the commands required to build your project, or remove this step entirely if your site is pre-built.
run: |
cd vue
npm install
npm run build
- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@3.7.1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: gh-pages # The branch the action should deploy to.
FOLDER: vue/dist # The folder the action should deploy.
CLEAN: true # Automatically remove deleted files from the deploy branch
47 changes: 47 additions & 0 deletions .github/workflows/pi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# This workflow makes a 64 bit Raspberry Pi Arch Linux Image.
# It does not have the security issues mentioned here: https://github.com/tendermint/tendermint/blob/master/docs/tendermint-core/running-in-production.md#validator-signing-on-32-bit-architectures-or-arm
# Later, more devices will be supported, as well.
# The "base" is built by: https://github.com/faddat/sos
# The base image is located at: https://hub.docker.com/r/faddat/spos
# TODO: Replace this with a system that fetches SOS-light, loop-mounts the image, modifies hostname, adds docker compose run, and exits.

name: Rpi
on: []

jobs:
pi:
name: frontierchain Pi
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2

- name: Set up QEMU
run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes --credential yes

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
with:
version: latest

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build Image in Docker
run: docker buildx build --tag frontierchain --file .pi/Dockerfile --platform linux/arm64 --cache-from ${{ secrets.DOCKERHUB_USERNAME }}/frontierchain:picache --cache-to ${{ secrets.DOCKERHUB_USERNAME }}/frontierchain:picache --load --progress tty .

- name: Build Image
run: bash .pi/build.sh

- name: Compress
run: xz -T $(nproc) images/frontierchain.img

- name: Upload image
uses: actions/upload-artifact@v2
with:
name: Starport Pi
path: images/frontierchain.img.xz
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
vue/node_modules
vue/dist
vue/.cache
build
readme.md
8 changes: 8 additions & 0 deletions .pi/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM faddat/sos-lite

# Add seeds and such after doing gaia.
# I will prototype the rest of this on gaia.
RUN echo frontierchain > /etc/hostname && \
pacman -Syyu --noconfirm docker-compose zerotier-one
# echo "docker run frontierdotxyz/frontier" >> /usr/local/bin/firstboot.sh
# TODO: docker-compose
90 changes: 90 additions & 0 deletions .pi/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/bin/bash
# =======================================================================
# Starport Development Environment Build System
# =======================================================================


# This process uses tools and a design pattern first developed by the pikvm team for their pi-builder and os tools.
# the biggest differences between this process and theirs are:
# * we use docker buildx so we don't need to deal with qemu directly.
# * we are not offering as many choices to users and are designing around automation.
# Later we can make this work for more devices and platforms with nearly the same technique.
# Reasonable build targets include: https://archlinuxarm.org/platforms/armv8
# For example, the Odroid-N2 is the same software-wise as our Router!

# Fail on error
set -exo pipefail

# Print each command
set -o xtrace

# EXTRACT IMAGE
# Make a temporary directory
rm -rf .tmp || true
mkdir .tmp

# UNCOMMENT and add username WHEN NOT USING GITHUB ACTIONS
# docker buildx build --tag frontierchain --file .pi/Dockerfile --platform linux/arm64 --cache-from frontierchain:cache --cache-to frontierchain:cache --load --progress tty .

# save the image to result-rootfs.tar
docker save --output ./.tmp/result-rootfs.tar frontierchain

# Extract the image using docker-extract
docker run --rm --tty --volume $(pwd)/./.tmp:/root/./.tmp --workdir /root/./.tmp/.. faddat/toolbox /tools/docker-extract --root ./.tmp/result-rootfs ./.tmp/result-rootfs.tar

# get rid of result-rootfs.tar to save space
rm ./.tmp/result-rootfs.tar

# Set hostname while the image is just in the filesystem.
sudo bash -c "echo frontierchain > ./.tmp/result-rootfs/etc/hostname"


# ===================================================================================
# IMAGE: Make a .img file and compress it.
# Uses Techniques from Disconnected Systems:
# https://disconnected.systems/blog/raspberry-pi-archlinuxarm-setup/
# ===================================================================================


# Unmount anything on the loop device
sudo umount /dev/loop0p2 || true
sudo umount /dev/loop0p1 || true

# Detach from the loop device
sudo losetup -d /dev/loop0 || true

# Create a folder for images
rm -rf images || true
mkdir -p images

# Make the image file
fallocate -l 4G "images/frontierchain.img"

# loop-mount the image file so it becomes a disk
sudo losetup --find --show images/frontierchain.img

# partition the loop-mounted disk
sudo parted --script /dev/loop0 mklabel msdos
sudo parted --script /dev/loop0 mkpart primary fat32 0% 200M
sudo parted --script /dev/loop0 mkpart primary ext4 200M 100%

# format the newly partitioned loop-mounted disk
sudo mkfs.vfat -F32 /dev/loop0p1
sudo mkfs.ext4 -F /dev/loop0p2

# Use the toolbox to copy the rootfs into the filesystem we formatted above.
# * mount the disk's /boot and / partitions
# * use rsync to copy files into the filesystem
# make a folder so we can mount the boot partition
# soon will not use toolbox

sudo mkdir -p mnt/boot mnt/rootfs
sudo mount /dev/loop0p1 mnt/boot
sudo mount /dev/loop0p2 mnt/rootfs
sudo rsync -a ./.tmp/result-rootfs/boot/* mnt/boot
sudo rsync -a ./.tmp/result-rootfs/* mnt/rootfs --exclude boot
sudo mkdir mnt/rootfs/boot
sudo umount mnt/boot mnt/rootfs || true

# Drop the loop mount
sudo losetup -d /dev/loop0
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Compile
FROM golang:alpine AS builder
WORKDIR /src/app/
COPY go.mod go.sum* ./
RUN go mod download
COPY . .
RUN for bin in cmd/*; do CGO_ENABLED=0 go build -o=/usr/local/bin/$(basename $bin) ./cmd/$(basename $bin); done


# Add to a distroless container
FROM gcr.io/distroless/base
COPY --from=builder /usr/local/bin /usr/local/bin
USER nonroot:nonroot
CMD ["frontierchaind start"]
Loading

0 comments on commit e5945d2

Please sign in to comment.