Skip to content

Commit

Permalink
Update to run on x86 (#5)
Browse files Browse the repository at this point in the history
* convert to run on x86

* make build process multi arch compatible

* optimize build layer

* update Makefile and README to best practices

* Update README.md

Co-authored-by: Chris Guida <[email protected]>

* update readme

* update readme to link to packaging docs

* rename folders/file

* convert health checks to js

* update copy and deps version

Co-authored-by: Chris Guida <[email protected]>
  • Loading branch information
elvece and chrisguida authored Nov 4, 2022
1 parent 369005e commit d166533
Show file tree
Hide file tree
Showing 15 changed files with 115 additions and 160 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ gitea.s9pk
image.tar
scripts/embassy.js
.vscode
docker-images
11 changes: 2 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
FROM gitea/gitea:1.16.9

RUN apk update
RUN apk add --no-cache tini curl

RUN wget https://github.com/mikefarah/yq/releases/download/v4.27.2/yq_linux_arm.tar.gz -O - |\
tar xz && mv yq_linux_arm /usr/bin/yq
RUN apk add --no-cache tini curl yq --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community

ADD ./docker_entrypoint.sh /usr/local/bin/docker_entrypoint.sh
RUN chmod a+x /usr/local/bin/docker_entrypoint.sh
ADD ./check-web.sh /usr/local/bin/check-web.sh
RUN chmod +x /usr/local/bin/check-web.sh
ADD ./check-user-signups-off.sh /usr/local/bin/check-user-signups-off.sh
RUN chmod +x /usr/local/bin/check-user-signups-off.sh
RUN chmod a+x /usr/local/bin/docker_entrypoint.sh
30 changes: 19 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
ASSETS := $(shell yq e '.assets.[].src' manifest.yaml)
VERSION := $(shell yq e ".version" manifest.yaml)
S9PK_PATH=$(shell find . -name gitea.s9pk -print)
PKG_VERSION := $(shell yq e ".version" manifest.yaml)
PKG_ID := $(shell yq e ".id" manifest.yaml)
TS_FILES := $(shell find . -name \*.ts )

# delete the target of a rule if it has changed and its recipe exits with a nonzero exit status
.DELETE_ON_ERROR:

all: verify

install: gitea.s9pk
embassy-cli package install gitea.s9pk
# assumes /etc/embassy/config.yaml exists on local system with `host: "http://embassy-server-name.local"` configured
install: $(PKG_ID).s9pk
embassy-cli package install $(PKG_ID).s9pk

verify: gitea.s9pk $(S9PK_PATH)
embassy-sdk verify s9pk $(S9PK_PATH)
verify: $(PKG_ID).s9pk
embassy-sdk verify s9pk $(PKG_ID).s9pk

clean:
rm -rf docker-images
rm -f $(PKG_ID).s9pk
rm -f image.tar
rm -f gitea.s9pk
rm -f scripts/*.js

gitea.s9pk: manifest.yaml image.tar instructions.md scripts/embassy.js
$(PKG_ID).s9pk: manifest.yaml instructions.md scripts/embassy.js gitea/LICENSE docker-images/aarch64.tar docker-images/x86_64.tar
if ! [ -z "$(ARCH)" ]; then cp docker-images/$(ARCH).tar image.tar; fi
embassy-sdk pack

image.tar: Dockerfile docker_entrypoint.sh check-web.sh
DOCKER_CLI_EXPERIMENTAL=enabled docker buildx build --tag start9/gitea/main:$(VERSION) --platform=linux/arm64 -o type=docker,dest=image.tar .
docker-images/aarch64.tar: Dockerfile docker_entrypoint.sh
mkdir -p docker-images
DOCKER_CLI_EXPERIMENTAL=enabled docker buildx build --tag start9/$(PKG_ID)/main:$(PKG_VERSION) --platform=linux/arm64 -o type=docker,dest=docker-images/aarch64.tar .

docker-images/x86_64.tar: Dockerfile docker_entrypoint.sh
mkdir -p docker-images
DOCKER_CLI_EXPERIMENTAL=enabled docker buildx build --tag start9/$(PKG_ID)/main:$(PKG_VERSION) --platform=linux/amd64 -o type=docker,dest=docker-images/x86_64.tar .

scripts/embassy.js: $(TS_FILES)
deno bundle scripts/embassy.ts scripts/embassy.js
38 changes: 22 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
# Wrapper for gitea

`Gitea` is a community managed lightweight code hosting solution written in Go.
It is published under the MIT license.
Gitea is a community managed lightweight code hosting solution written in Go.
It is published under the MIT license. This repository creates the `s9pk` package that is installed to run `gitea` on [embassyOS](https://github.com/Start9Labs/embassy-os/).

## Dependencies

Install the system dependencies below to build this project by following the instructions in the provided links. You can also find detailed steps to setup your environment in the service packaging [documentation](https://github.com/Start9Labs/service-pipeline#development-environment).

- [docker](https://docs.docker.com/get-docker)
- [docker-buildx](https://docs.docker.com/buildx/working-with-buildx/)
- [yq](https://mikefarah.gitbook.io/yq)
- [deno](https://deno.land/)
- [deno](https://deno.land/#installation)
- [make](https://www.gnu.org/software/make/)
- [embassy-sdk](https://github.com/Start9Labs/embassy-os/tree/master/backend)

## Build enviroment
## Build environment

Prepare your EmbassyOS build enviroment. In this example we are using Ubuntu
20.04.
Prepare your EmbassyOS build environment. In this example we are using Ubuntu 20.04.

1. Install docker

Expand Down Expand Up @@ -64,12 +65,11 @@ make sdk
embassy-sdk init
```

Now you are ready to build your gitea service
Now you are ready to build the `gitea` package

## Cloning

Clone the gitea wrapper locally. Note the submodule link to the original
project.
Clone the Gitea Wrapper locally. Note the submodule link to the original project.

```
git clone https://github.com/Start9Labs/gitea-wrapper.git
Expand All @@ -79,22 +79,22 @@ git submodule update --init

## Building

To build the gitea service, run the following commands:
To build the `gitea` package, run the following command:

```
make
```

## Installing (on Embassy)
## Installing (on embassyOS)

Run the following commands to install:

> :information_source: Change embassy-q1w2e3r.local to your Embassy address
> :information_source: Change embassy-server-name.local to your Embassy address
```
embassy-cli auth login
#Enter your embassy password
embassy-cli --host https://embassy-q1w2e3r4.local package install gitea.s9pk
# Enter your embassy password
embassy-cli --host https://embassy-server-name.local package install gitea.s9pk
```

If you already have your `embassy-cli` config file setup with a default `host`,
Expand All @@ -104,5 +104,11 @@ you can install simply by running:
make install
```

**Tip:** You can also install the gitea.s9pk using **Sideload Service** under
the **Embassy>SETTINGS** section.
> **Tip:** You can also install the gitea.s9pk using **Sideload Service** under
the **Embassy > Settings** section.
### Verify Install

Go to your Embassy Services page, select **Gitea**, configure and start the service. Then, verify its interfaces are accessible.

**Done!**
10 changes: 0 additions & 10 deletions check-user-signups-off.sh

This file was deleted.

11 changes: 0 additions & 11 deletions check-web.sh

This file was deleted.

24 changes: 6 additions & 18 deletions manifest.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
id: gitea
title: "Gitea"
version: 1.16.9
version: 1.16.9.1
release-notes: |
Initial release of Gitea for EmbassyOS
Upgrade to run on x86_64 architecture
license: MIT
wrapper-repo: "https://github.com/chrisguida/gitea-wrapper"
upstream-repo: "https://github.com/go-gitea/gitea"
Expand All @@ -26,24 +26,12 @@ main:
main: /data
health-checks:
web:
name: HTTP Interface (Web & Git HTTP over Tor)
success-message: Gitea is ready to be visited in your browser, and your git repos can now be interacted with.
type: docker
image: main
entrypoint: check-web.sh
args: ["web"]
io-format: json
inject: true
name: Web & Git HTTP Tor Interfaces
success-message: Gitea is ready to be visited in a web browser and git can be used with SSH over TOR.
type: script
user-signups-off:
name: User Signups Off
type: docker
image: main
system: false
entrypoint: check-user-signups-off.sh
args: []
mounts: {}
io-format: yaml
inject: true
type: script
config:
get:
type: script
Expand Down
2 changes: 1 addition & 1 deletion scripts/deps.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "https://deno.land/x/[email protected].2/mod.ts";
export * from "https://deno.land/x/[email protected].4/mod.ts";
9 changes: 5 additions & 4 deletions scripts/embassy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { properties } from "./services/properties.ts";
export { setConfig } from "./services/setConfig.ts";
export { getConfig } from "./services/getConfig.ts";
export { migration } from "./services/migrations.ts";
export { properties } from "./procedures/properties.ts";
export { setConfig } from "./procedures/setConfig.ts";
export { getConfig } from "./procedures/getConfig.ts";
export { migration } from "./procedures/migrations.ts";
export { health } from "./procedures/healthChecks.ts";
File renamed without changes.
57 changes: 57 additions & 0 deletions scripts/procedures/healthChecks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { types as T, matches, util } from "../deps.ts";
import { getConfig } from "./getConfig.ts";

export const health: T.ExpectedExports.health = {
// deno-lint-ignore require-await
async "web"(effects, duration) {
return healthWeb(effects, duration);
},
// deno-lint-ignore require-await
async "user-signups-off"(effects, duration) {
return healthSignups(effects, duration);
},
};

const healthWeb: T.ExpectedExports.health[""] = async (effects, duration) => {
await guardDurationAboveMinimum({ duration, minimumTime: 5000 });

return await effects.fetch("http://gitea.embassy:3000")
.then((_) => ok)
.catch((e) => {
effects.error(`${e}`)
return error(`The Gitea UI is unreachable`)
});
};

const healthSignups: T.ExpectedExports.health[""] = async (effects, duration) => {
await guardDurationAboveMinimum({ duration, minimumTime: 5000 });
const config = (util.unwrapResultType(await getConfig(effects))).config!
if (!matchRegistration.test(config)) {
throw `Could not find "disable-registration" key in config: ${matchRegistration.errorMessage(config)}`
}
if (!config['disable-registration']) {
return error("For security purposes, user account registration should be disabled when not in use. You can disable registration in Config settings.")
}
return ok
}

// *** HELPER FUNCTIONS *** //

const { shape, boolean } = matches
const matchRegistration = shape({
'disable-registration': boolean
})

// Ensure the starting duration is past a minimum
const guardDurationAboveMinimum = (
input: { duration: number; minimumTime: number },
) =>
(input.duration <= input.minimumTime)
? Promise.reject(errorCode(60, "Starting"))
: null;

const errorCode = (code: number, error: string) => ({
"error-code": [code, error] as const,
});
const error = (error: string) => ({ error });
const ok = { result: null };
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { compat, types as T } from "../deps.ts";

export const migration: T.ExpectedExports.migration = compat.migrations
.fromMapping( {}, "1.16.9" );
.fromMapping( {}, "1.16.9.1" );
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import { compat, types as T } from "../deps.ts";

// deno-lint-ignore require-await
export const setConfig: T.ExpectedExports.setConfig = async (
effects: T.Effects,
newConfig: T.Config,
Expand Down
78 changes: 0 additions & 78 deletions scripts/services/health.ts

This file was deleted.

0 comments on commit d166533

Please sign in to comment.