Skip to content

Commit

Permalink
feat: PairDrop StartOS package (#1)
Browse files Browse the repository at this point in the history
* wip

* fix: devcontainer

* fix: update icon

* fix: add Dockerfile

* ci: add CIs

* fix: Makefile

* fix: readme

* fix: dockerfile

* fix: Update instructions for PairDrop

* chore: Update description for User Interface in manifest.yaml

* ci: Upload .s9pk artifact

* chore: Remove npm start from Dockerfile and add docker_entrypoint.sh

* chore: Update artifact upload step in buildService.yml

* chore: Update Dockerfile and docker_entrypoint.sh for production deployment

* another try
  • Loading branch information
storopoli authored May 17, 2024
1 parent b7700e6 commit d894966
Show file tree
Hide file tree
Showing 18 changed files with 338 additions and 168 deletions.
23 changes: 23 additions & 0 deletions .devcontainer/deno.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh

# set error
set -e

# Move to a tempdir
cd "$(mktemp -d)"

# Hardcoded to deno 1.42.4
curl -LO https://github.com/denoland/deno/releases/download/v1.42.4/deno-x86_64-unknown-linux-gnu.zip

# Check the checksum
echo "8f769ded5ec44511ee8410c6389174e79c9d142cb4e47385d7358b552c63bdb9 deno-x86_64-unknown-linux-gnu.zip" | sha256sum -c -

# unzip
unzip deno-x86_64-unknown-linux-gnu.zip
sudo mv deno /usr/bin/deno

# remove everything
rm -rf -- *

# test command
deno --version
45 changes: 45 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"name": "Start9 App Builder",
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers/features/python:1": {},
"ghcr.io/devcontainers-contrib/features/apt-get-packages:1": {
"packages": "build-essential,openssl,libssl-dev,libc6-dev,clang,libclang-dev,ca-certificates,curl,cargo"
}
},

// Configure tool-specific properties.
"customizations": {
"vscode": {
"extensions": [
"ms-azuretools.vscode-docker",
"ms-python.python",
"mads-hartmann.bash-ide-vscode",
"timonwong.shellcheck",
"tamasfe.even-better-toml",
"github.vscode-github-actions",
"GitHub.copilot",
"GitHub.copilot-chat",
"DavidAnson.vscode-markdownlint",
"wayou.vscode-todo-highlight"
]
}
},

// Install stuff not packaged in Ubuntu
"onCreateCommand": {
"yq": "./.devcontainer/yq.sh",
"deno": "./.devcontainer/deno.sh"
},
"postCreateCommand": {
"start9": "./.devcontainer/start9.sh"
},

// Add start-sdk to the PATH
"containerEnv": {
"PATH": "$HOME/.cargo/bin:$PATH"
},

"remoteUser": "vscode"
}
13 changes: 13 additions & 0 deletions .devcontainer/start9.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh

# set error
set -e

# move to a homedir
mkdir "$HOME/start9" && cd "$HOME/start9" && pwd

# Start9 SDK
git clone --recursive https://github.com/Start9Labs/start-os.git --branch sdk
cd start-os/
make sdk
start-sdk init
23 changes: 23 additions & 0 deletions .devcontainer/yq.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh

# set error
set -e

# Move to a tempdir
cd "$(mktemp -d)"

# Hardcoded to yq 4.43.1
curl -LO https://github.com/mikefarah/yq/releases/download/v4.43.1/yq_linux_amd64.tar.gz

# Check the checksum
echo "049d1f3791cc25160a71b0bbe14a58302fb6a7e4462e07d5cbd543787a9ad815 yq_linux_amd64.tar.gz" | sha256sum -c -

# untar
tar -xzf yq_linux_amd64.tar.gz
sudo mv yq_linux_amd64 /usr/bin/yq

# remove everything
rm -rf -- *

# test command
yq --version
14 changes: 14 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: monthly
- package-ecosystem: "gitsubmodule"
directory: "/"
schedule:
interval: monthly
- package-ecosystem: "devcontainers"
directory: "/"
schedule:
interval: monthly
36 changes: 36 additions & 0 deletions .github/workflows/buildService.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Build Service

on:
workflow_dispatch:
pull_request:
paths-ignore: ["*.md"]
branches: ["main", "master"]
push:
paths-ignore: ["*.md"]
branches: ["main", "master"]

jobs:
BuildPackage:
runs-on: ubuntu-latest
steps:
- name: Prepare StartOS SDK
uses: Start9Labs/sdk@v1

- name: Checkout services repository
uses: actions/checkout@v4

- name: Build the service package
id: build
run: |
git submodule update --init --recursive
start-sdk init
make
PACKAGE_ID=$(yq -oy ".id" manifest.*)
echo "package_id=$PACKAGE_ID" >> $GITHUB_ENV
shell: bash

- name: Upload .s9pk
uses: actions/upload-artifact@v4
with:
name: ${{ env.package_id }}.s9pk
path: ./${{ env.package_id }}.s9pk
71 changes: 71 additions & 0 deletions .github/workflows/releaseService.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Release Service

on:
push:
tags:
- 'v*.*'

jobs:
ReleasePackage:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Prepare StartOS SDK
uses: Start9Labs/sdk@v1

- name: Checkout services repository
uses: actions/checkout@v4

- name: Build the service package
run: |
git submodule update --init --recursive
start-sdk init
make
- name: Setting package ID and title from the manifest
id: package
run: |
echo "package_id=$(yq -oy ".id" manifest.*)" >> $GITHUB_ENV
echo "package_title=$(yq -oy ".title" manifest.*)" >> $GITHUB_ENV
shell: bash

- name: Generate sha256 checksum
run: |
PACKAGE_ID=${{ env.package_id }}
sha256sum ${PACKAGE_ID}.s9pk > ${PACKAGE_ID}.s9pk.sha256
shell: bash

- name: Generate changelog
run: |
PACKAGE_ID=${{ env.package_id }}
echo "## What's Changed" > change-log.txt
yq -oy '.release-notes' manifest.* >> change-log.txt
echo "## SHA256 Hash" >> change-log.txt
echo '```' >> change-log.txt
sha256sum ${PACKAGE_ID}.s9pk >> change-log.txt
echo '```' >> change-log.txt
shell: bash

- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
name: ${{ env.package_title }} ${{ github.ref_name }}
prerelease: true
body_path: change-log.txt
files: |
./${{ env.package_id }}.s9pk
./${{ env.package_id }}.s9pk.sha256
- name: Publish to Registry
env:
S9USER: ${{ secrets.S9USER }}
S9PASS: ${{ secrets.S9PASS }}
S9REGISTRY: ${{ secrets.S9REGISTRY }}
run: |
if [[ -z "$S9USER" || -z "$S9PASS" || -z "$S9REGISTRY" ]]; then
echo "Publish skipped: missing registry credentials."
else
start-sdk publish https://$S9USER:$S9PASS@$S9REGISTRY ${{ env.package_id }}.s9pk
fi
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "hello-world"]
path = hello-world
url = https://github.com/Start9Labs/hello-world
[submodule "pairdrop"]
path = pairdrop
url = https://github.com/schlagmichdoch/pairdrop
23 changes: 14 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
FROM alpine:3.17
FROM node:lts-alpine

RUN apk update
RUN apk add --no-cache tini && \
rm -f /var/cache/apk/*
WORKDIR /home/node/app

ARG ARCH
ADD ./hello-world/target/${ARCH}-unknown-linux-musl/release/hello-world /usr/local/bin/hello-world
RUN chmod +x /usr/local/bin/hello-world
ADD ./docker_entrypoint.sh /usr/local/bin/docker_entrypoint.sh
RUN chmod a+x /usr/local/bin/docker_entrypoint.sh
COPY ./pairdrop/package*.json ./

RUN npm ci

COPY ./pairdrop .

# environment settings
ENV NODE_ENV="production"

EXPOSE 3000

ENTRYPOINT ["npm", "start"]
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Start9 Labs
Copyright (c) 2024 Casa21

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
24 changes: 4 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
PKG_ID := $(shell yq e ".id" manifest.yaml)
PKG_VERSION := $(shell yq e ".version" manifest.yaml)
TS_FILES := $(shell find ./ -name \*.ts)
HELLO_WORLD_SRC := $(shell find ./hello-world/src) hello-world/Cargo.toml hello-world/Cargo.lock

# delete the target of a rule if it has changed and its recipe exits with a nonzero exit status
.DELETE_ON_ERROR:
Expand Down Expand Up @@ -29,36 +28,27 @@ clean-manifest:
@sed -i '' '/^[[:blank:]]*#/d' manifest.yaml
@echo; echo "Comments successfully removed from manifest.yaml file."; echo

# BEGIN REBRANDING
rebranding:
@read -p "Enter new package ID name (must be a single word): " NEW_PKG_ID; \
read -p "Enter new package title: " NEW_PKG_TITLE; \
find . \( -name "*.md" -o -name ".gitignore" -o -name "manifest.yaml" -o -name "*Service.yml" \) -type f -not -path "./hello-world/*" -exec sed -i '' -e "s/hello-world/$$NEW_PKG_ID/g; s/Hello World/$$NEW_PKG_TITLE/g" {} +; \
echo; echo "Rebranding complete."; echo " New package ID name is: $$NEW_PKG_ID"; \
echo " New package title is: $$NEW_PKG_TITLE"; \
sed -i '' -e '/^# BEGIN REBRANDING/,/^# END REBRANDING/ s/^#*/#/' Makefile
@echo; echo "Note: Rebranding code has been commented out in Makefile"; echo
# END REBRANDING

scripts/embassy.js: $(TS_FILES)
deno bundle scripts/embassy.ts scripts/embassy.js

arm:
# this is not a typo, when building arm, remove the x86_64 image so it doesn't get packed by start-sdk
@rm -f docker-images/x86_64.tar
ARCH=aarch64 $(MAKE)

x86:
# this is not a typo, when building x86, remove the aarch64 image so it doesn't get packed by start-sdk
@rm -f docker-images/aarch64.tar
ARCH=x86_64 $(MAKE)

docker-images/aarch64.tar: Dockerfile docker_entrypoint.sh hello-world/target/aarch64-unknown-linux-musl/release/hello-world
docker-images/aarch64.tar: Dockerfile
ifeq ($(ARCH),x86_64)
else
mkdir -p docker-images
docker buildx build --tag start9/$(PKG_ID)/main:$(PKG_VERSION) --build-arg ARCH=aarch64 --platform=linux/arm64 -o type=docker,dest=docker-images/aarch64.tar .
endif

docker-images/x86_64.tar: Dockerfile docker_entrypoint.sh hello-world/target/x86_64-unknown-linux-musl/release/hello-world
docker-images/x86_64.tar: Dockerfile
ifeq ($(ARCH),aarch64)
else
mkdir -p docker-images
Expand All @@ -74,9 +64,3 @@ else
@echo "start-sdk: Preparing Universal Package ..."
endif
@start-sdk pack

hello-world/target/aarch64-unknown-linux-musl/release/hello-world: $(HELLO_WORLD_SRC)
docker run --rm -it -v ~/.cargo/registry:/root/.cargo/registry -v "$(shell pwd)"/hello-world:/home/rust/src messense/rust-musl-cross:aarch64-musl cargo build --release

hello-world/target/x86_64-unknown-linux-musl/release/hello-world: $(HELLO_WORLD_SRC)
docker run --rm -it -v ~/.cargo/registry:/root/.cargo/registry -v "$(shell pwd)"/hello-world:/home/rust/src messense/rust-musl-cross:x86_64-musl cargo build --release
Loading

0 comments on commit d894966

Please sign in to comment.