Skip to content

Commit

Permalink
Merge pull request #1 from spectrocloud/nianyu/install
Browse files Browse the repository at this point in the history
  • Loading branch information
nianyush authored Oct 5, 2024
2 parents e892f46 + a0b95cc commit 1944e91
Show file tree
Hide file tree
Showing 11 changed files with 330 additions and 1 deletion.
14 changes: 14 additions & 0 deletions .github/workflows/precommit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: pre-commit

on:
pull_request:
push:
branches: [main]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: pre-commit/[email protected]
38 changes: 38 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Release

on:
push:

permissions:
contents: write

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

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@master
with:
platforms: all
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@master
- name: Install earthly
uses: earthly/actions-setup@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
version: "latest"
use-cache: true
- name: Run Release target
run: earthly --ci --output +release
- name: Release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
files: build/*
46 changes: 46 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
bin/*
.netrc

# custom arg files
*.arg

# env files
*.env

# Test binary, build with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out


vendor
!vendor/**/zz_generated.*

# editor and IDE paraphernalia
.idea
*.swp
*.swo
*~
a

# cred file for docker build
.netrc
_build
.scannerwork
.fossa.yml
.DS_Store
.temp
local

outputs/
build/*
*_local*
*__debug_bin*
*.vscode*
29 changes: 29 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# install pre-commit on your system and then
# run pre-commit install in this repository.
# You can by pass commit hooks with:
# git commit -n
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-yaml
stages: [commit]
- id: check-json
stages: [commit]
- id: check-toml
stages: [commit]
- id: check-merge-conflict
stages: [commit]
- id: check-case-conflict
stages: [commit]
- id: detect-private-key
stages: [commit]
- repo: https://github.com/crate-ci/typos
rev: v1.25.0
hooks:
- id: typos
- repo: https://github.com/compilerla/conventional-pre-commit
rev: v3.4.0
hooks:
- id: conventional-pre-commit
stages: [commit-msg]
93 changes: 93 additions & 0 deletions Earthfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
VERSION 0.8

ARG --global SPECTRO_PUB_REPO=us-docker.pkg.dev/palette-images
ARG --global UBUNTU_IMAGE=${SPECTRO_PUB_REPO}/third-party/ubuntu:22.04
FROM ${UBUNTU_IMAGE}

release:
BUILD +package-tar \
--PLATFORM=linux \
--ARCH=amd64 \
--ARCH=arm64

BUILD +palette-agent \
--PLATFORM=linux \
--ARCH=amd64 \
--ARCH=arm64

BUILD +install-script

ubuntu:
FROM ${UBUNTU_IMAGE}
RUN apt-get update && apt-get install -y systemctl gettext-base
COPY PE_VERSION PE_VERSION

stylus-image:
ARG PLATFORM=linux
ARG ARCH=amd64
ARG STYLUS_IMAGE
FROM --platform=$PLATFORM/$ARCH $STYLUS_IMAGE
SAVE ARTIFACT --keep-own ./*

palette-agent:
FROM +ubuntu

ARG VERSION=$(head -n 1 PE_VERSION)
ARG PLATFORM=linux
ARG ARCH=amd64
ARG STYLUS_IMAGE=${SPECTRO_PUB_REPO}/edge/stylus-agent-mode-${PLATFORM}-${ARCH}:${VERSION}

WORKDIR /workdir
COPY (+stylus-image/opt/spectrocloud/bin/palette-agent --PLATFORM=${PLATFORM} --ARCH=${ARCH} --STYLUS_IMAGE=${STYLUS_IMAGE}) /workdir/
RUN chmod +x /workdir/palette-agent

SAVE ARTIFACT --keep-own /workdir/palette-agent AS LOCAL ./build/palette-agent-${PLATFORM}-${ARCH}

package-tar:
FROM +ubuntu

ARG VERSION=$(head -n 1 PE_VERSION)
ARG PLATFORM=linux
ARG ARCH=amd64
ARG STYLUS_IMAGE=${SPECTRO_PUB_REPO}/edge/stylus-agent-mode-${PLATFORM}-${ARCH}:${VERSION}
ARG TAR_NAME=agent-mode-${PLATFORM}-${ARCH}

WORKDIR /workdir/var/lib/spectro
COPY (+stylus-image/ --PLATFORM=${PLATFORM} --ARCH=${ARCH} --STYLUS_IMAGE=${STYLUS_IMAGE}) /workdir/var/lib/spectro/stylus

COPY package/tar/spectro-init.service /etc/systemd/system/spectro-init.service
COPY package/tar/spectro-init.sh /workdir/var/lib/spectro/spectro-init.sh
RUN mkdir -p /workdir/etc/systemd/system
RUN cp -rfv /workdir/var/lib/spectro/stylus/etc/systemd/system/spectro* /etc/systemd/system/
RUN cp -rfv /etc/systemd/system/spectro* /workdir/etc/systemd/system/

RUN for service in /etc/systemd/system/spectro*; do systemctl enable "$(basename "$service")"; done

RUN mkdir -p /workdir/etc/systemd/system/multi-user.target.wants
RUN cp -rfv /etc/systemd/system/multi-user.target.wants/spectro* /workdir/etc/systemd/system/multi-user.target.wants/
RUN mkdir -p /workdir/etc/systemd/system/local-fs.target.wants
RUN cp -rfv /etc/systemd/system/local-fs.target.wants/spectro* /workdir/etc/systemd/system/local-fs.target.wants/
RUN mkdir -p /workdir/etc/systemd/system/sysinit.target.wants
RUN cp -rfv /etc/systemd/system/sysinit.target.wants/spectro* /workdir/etc/systemd/system/sysinit.target.wants/

RUN tar -cvf /${TAR_NAME}.tar -C /workdir .

SAVE ARTIFACT /${TAR_NAME}.tar AS LOCAL ./build/

install-script:
FROM +ubuntu

ARG VERSION=$(head -n 1 PE_VERSION)
ARG IMAGE_REPO=${SPECTRO_PUB_REPO}/edge
ARG AGENT_URL_PREFIX=https://github.com/spectrocloud/agent-mode/releases/latest/download

ENV PE_VERSION=${VERSION}
ENV IMAGE_REPO=${IMAGE_REPO}
ENV AGENT_URL_PREFIX=${AGENT_URL_PREFIX}

WORKDIR /workdir
COPY install.sh.tmpl /workdir/install.sh.tmpl
RUN envsubst '${PE_VERSION} ${IMAGE_REPO} ${AGENT_URL_PREFIX}' < /workdir/install.sh.tmpl > /workdir/install.sh
RUN chmod +x /workdir/install.sh

SAVE ARTIFACT --keep-own /workdir/install.sh AS LOCAL ./build/install.sh
1 change: 1 addition & 0 deletions PE_VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v4.5.0-rc4
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
# agent-mode
# agent-mode

## Quick Start

```bash
curl https://github.com/spectrocloud/agent-mode/releases/latest/download/install.sh | bash
```

## Usage

### specify userdata

Userdata can be a URL or a file path.

```bash
curl https://github.com/spectrocloud/agent-mode/releases/latest/download/install.sh | USERDATA=https://xxx/userdata bash
# or
curl https://github.com/spectrocloud/agent-mode/releases/latest/download/install.sh | USERDATA=/path/to/userdata bash
```

### specify palette version

```bash
curl https://github.com/spectrocloud/agent-mode/releases/latest/download/install.sh | VERSION=v4.5.0 bash
```
32 changes: 32 additions & 0 deletions install.sh.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash
set -e
# set -x

# Get the platform architecture
ARCH=$(uname -m)
VERSION=${PE_VERSION}

# Check the architecture and print the appropriate message
if [ "$ARCH" == "x86_64" ]; then
ARCH=amd64
elif [ "$ARCH" == "aarch64" ] || [ "$ARCH" == "arm64" ]; then
ARCH=arm64
else
echo "Unsupported architecture: $ARCH"
fi

IMAGE=${IMAGE_REPO}/stylus-agent-mode-linux-${ARCH}:${VERSION}
URL=${AGENT_URL_PREFIX}/palette-agent-${VERSION}-linux-${ARCH}

# Download edge-agent
curl -v -L $URL -o palette-agent
chmod +x palette-agent

# Install with palette-agent
if [ -z "$USER_DATA" ]; then
# Install without user data
./palette-agent install --source $IMAGE
else
# Install with user data
./palette-agent install --source $IMAGE --config "$USER_DATA"
fi
10 changes: 10 additions & 0 deletions package/tar/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
set -e
# set -x # Uncomment for debugging

unpack() {
TAR_FILE=$1
tar -xvf $TAR_FILE -C /
}

unpack $1
14 changes: 14 additions & 0 deletions package/tar/spectro-init.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Unit]
Description=Spectro Initialization
Before=local-fs.target spectro-palette-agent-bootstrap.service

[Service]
ExecStart=/var/lib/spectro/spectro-init.sh
User=root
Group=root
Restart=on-failure
RemainAfterExit=yes
RestartSec=5s

[Install]
WantedBy=local-fs.target
28 changes: 28 additions & 0 deletions package/tar/spectro-init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
set -ex
if [ -f /etc/spectro/environment ]; then
. /etc/spectro/environment
fi

SENTINEL_FILE="${STYLUS_ROOT}/opt/spectrocloud/state/setup_done"

if [ -f ${SENTINEL_FILE} ]; then
echo "Setup already done"
exit
fi

export PATH=$PATH:/var/lib/spectro/stylus/opt/spectrocloud/bin
palette-agent install --source dir:/var/lib/spectro/stylus --config /var/lib/spectro/userdata

# reload the environment on first boot
if [ -f /etc/spectro/environment ]; then
. /etc/spectro/environment
fi

touch ${SENTINEL_FILE}
systemctl daemon-reload
systemctl restart spectro-palette-agent-start || true
systemctl restart spectro-palette-agent-initramfs || true
systemctl restart spectro-palette-agent-boot || true
systemctl restart spectro-palette-agent-network || true
systemctl restart spectro-palette-agent-bootstrap || true

0 comments on commit 1944e91

Please sign in to comment.