Skip to content

Commit

Permalink
Merge pull request #8 from seia-soto/rework-git-patch
Browse files Browse the repository at this point in the history
  • Loading branch information
seia-soto authored Feb 16, 2023
2 parents 24f3e36 + ceb61b7 commit f2287d5
Show file tree
Hide file tree
Showing 11 changed files with 201 additions and 136 deletions.
59 changes: 7 additions & 52 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,27 @@ jobs:
version:
runs-on: ubuntu-latest
outputs:
local_release: ${{steps.local.outputs.release}}
local_tag: ${{steps.local.outputs.tag}}
remote_release: ${{steps.remote.outputs.release}}
remote_tag: ${{steps.remote.outputs.tag}}
is_release_build_required: ${{steps.test.outputs.release}}
is_latest_build_required: ${{steps.test.outputs.latest}}
steps:
- name: Get remote version
id: remote
run: |
echo ::set-output name=tag::"$(curl -sL https://api.github.com/repos/Jigsaw-Code/outline-server/tags | jq -r '.[0].name')"
echo ::set-output name=release::"$(curl -sL https://api.github.com/repos/Jigsaw-Code/outline-server/releases | jq -r '[.[] | select(.prerelease == false)][0].tag_name')"
git clone https://github.com/Jigsaw-Code/outline-server.git outline-server
cd outline-server
echo "::set-output name=tag::$(git describe --tags --abbrev=0)"
- name: Get local release
id: local
run: |
echo ::set-output name=tag::"$(curl -sL "https://api.github.com/repos/${{github.repository}}/releases" | jq -r '[.[] | select(.tag_name | startswith("latest-"))][0].name')"
echo ::set-output name=release::"$(curl -sL "https://api.github.com/repos/${{github.repository}}/releases" | jq -r '[.[] | select(.tag_name | startswith("release-"))][0].tag_name')"
echo ::set-output name=tag::"$(curl -sL "https://api.github.com/repos/${{github.repository}}/releases" | jq -r '[.[] | select(.name | startswith("latest-"))][0].name')"
- name: Test
id: test
run: |
if [[ "latest-${{steps.remote.outputs.tag}}" != "${{steps.local.outputs.tag}}" ]];
then
echo "::set-output name=latest::true"
fi
if [[ "release-${{steps.remote.outputs.release}}" != "${{steps.local.outputs.release}}" ]];
then
echo "::set-output name=release::true"
fi
build_master:
needs: [version]
runs-on: ubuntu-20.04
Expand All @@ -62,7 +55,7 @@ jobs:
password: ${{secrets.GITHUB_TOKEN}}
- name: Build and push
run: |
bash ./build.sh "${{env.ARCH}}" "${{env.PACKAGE_NAME}}:master" "master" "false"
bash ./build.sh "${{env.ARCH}}" "${{env.PACKAGE_NAME}}:master" "master"
build_latest:
needs: [version]
runs-on: ubuntu-20.04
Expand All @@ -72,7 +65,7 @@ jobs:
uses: actions/checkout@v2
- uses: actions/setup-node@v3
with:
node-version: 12
node-version: 16
- name: Setup QEMU
uses: docker/setup-qemu-action@v1
with:
Expand All @@ -88,7 +81,7 @@ jobs:
password: ${{secrets.GITHUB_TOKEN}}
- name: Build and push
run: |
bash ./build.sh "${{env.ARCH}}" "${{env.PACKAGE_NAME}}:latest" "${{needs.version.outputs.remote_tag}}" "true"
bash ./build.sh "${{env.ARCH}}" "${{env.PACKAGE_NAME}}:latest" "${{needs.version.outputs.remote_tag}}"
- name: Conditional release
uses: actions/create-release@v1
env:
Expand All @@ -100,42 +93,4 @@ jobs:
This release is for identification use of CI script.
Please, read README to deploy this package.
draft: false
prerelease: true
build_release:
needs: [version]
runs-on: ubuntu-20.04
if: needs.version.outputs.is_release_build_required == 'true'
steps:
- name: Checkout repository
uses: actions/checkout@v2
- uses: actions/setup-node@v3
with:
node-version: 12
- name: Setup QEMU
uses: docker/setup-qemu-action@v1
with:
image: tonistiigi/binfmt:latest
platforms: all
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{github.repository_owner}}
password: ${{secrets.GITHUB_TOKEN}}
- name: Build and push
run: |
bash ./build.sh "${{env.ARCH}}" "${{env.PACKAGE_NAME}}:release" "${{needs.version.outputs.remote_release}}" "true"
- name: Conditional release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
with:
tag_name: "release-${{needs.version.outputs.remote_release}}"
release_name: "release-${{needs.version.outputs.remote_release}}"
body: |
This release is for identification use of CI script.
Please, read README to deploy this package.
draft: false
prerelease: false
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/workspace
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MIT License Copyright 2022 HoJeong Go
MIT License Copyright 2022-2023 HoJeong Go

Permission is hereby granted, free of
charge, to any person obtaining a copy of this software and associated
Expand Down
31 changes: 31 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
help:
@echo "use: $(MAKE) [clone-upstream]"
@echo ""
@echo " clone-upstream -> clone upstream(Jigsaw-Code/outline-server) into ./workspace/outline-server"
@echo " apply-patches -> patch diff files into ./workspace/outline-server"
@echo " create-patch -> create patch file from workspace TARGET=target_to_execute_diff"
@echo " clean -> clean workspace directory"

clone-upstream:
mkdir -p ./workspace;
@if [[ ! -d ./workspace/outline-server ]]; then \
git clone https://github.com/Jigsaw-Code/outline-server.git ./workspace/outline-server; \
else \
cd ./workspace/outline-server; \
git pull; \
fi;

apply-patches:
@cd ./workspace/outline-server; \
for FILE in ../../patches/*.patch; do \
[[ -e "$${FILE}" ]] || continue; \
echo "Applying $${FILE}"; \
git apply "$${FILE}"; \
done;

create-patch:
@cd ./workspace/outline-server; \
git diff $(TARGET) > ../../patches/_.patch;

clean:
rm -rf ./workspace/outline-server;
35 changes: 26 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ The multi-arch distribution of [Jigsaw's Outline-Server](https://github.com/Jigs
|---------|----------------------------------------------|-----------------|------------------------------------------------------|
| master | daily | upstream/master | linux/amd64, linux/arm64, linux/arm/v7, linux/arm/v6 |
| latest | checked daily, released as upstream tags | Latest tag | linux/amd64, linux/arm64, linux/arm/v7, linux/arm/v6 |
| release | checked daily, released as upstream releases | Latest release | linux/amd64, linux/arm64, linux/arm/v7, linux/arm/v6 |
| release | checked daily, not more updated (legacy) | v1.9 or lower | linux/amd64, linux/arm64, linux/arm/v7, linux/arm/v6 |

## Usage

To install outline-server on your server using this docker image, paste following code before install:

```bash
# master release, updated daily
# master release, updated daily (might fail sometime)
export SB_IMAGE="ghcr.io/seia-soto/shadowbox:master"

# stable release, updated infrequently
# stable release, NOT MORE UPDATED (It is for outline-server v1.9 or lower, use `latest` instead)
export SB_IMAGE="ghcr.io/seia-soto/shadowbox:release"

# latest release, updated irregularly
Expand All @@ -26,9 +26,21 @@ export SB_IMAGE="ghcr.io/seia-soto/shadowbox:latest"
curl -sL "https://raw.githubusercontent.com/Jigsaw-Code/outline-server/master/src/server_manager/install_scripts/install_server.sh" | sed '/local MACHINE_TYPE/,/fi/{d}' | bash
```

## Development

### Patching

There're Makefile in this repository and contains some useful commands for development, but you can continue only with `git diff` command.

Use `make help` to print help script.

Starting with `make clone-upstream apply-patches` would be help.

### Local build

To build local image, you can use following command with prepared environment:
> The build script uses Docker Buildx and you cannot publish the output image directly to the Docker daemon.
To build image locally, you can use following command with prepared environment:

- For **single-arch** build, you just need to install:
- `jq`
Expand All @@ -52,16 +64,21 @@ cd outline-server-multiarch
Usage:
./build.sh $arch $tag $checkpoint $use_legacy_install
./build.sh $arch $tag $checkpoint
-- Arguments:
$arch {string} The arch to build, using docker platform style
$tag {string} The docker tag to use while building the image
$checkpoint {string} The git branch or tag to checkout on Jigsaw-Code/Outline-Server
$use_legacy_install {boolean} Set as true to build recent versions of outline-server using Node.JS v16 (likely on master branch)
-- Environments:
$AB_LEAVE_BASE_DIRECTORY {any} If it is not empty string, script will not clean working directory
About:
This script builds Outline-Server docker image
This script builds Outline-Server docker buildx image
with specific arch by downloading compatible third_party
automatically.
'
Expand All @@ -73,7 +90,7 @@ PLATFORM="linux/amd64" # use one of linux/amd64,linux/arm64,linux/arm/v7,linux/a
CHECKPOINT="latest" # use latest for latest tag or `master`

# build latest, use false for use_legacy_install if you're building master branch
bash ./build.sh "${PLATFORM}" "${SB_IMAGE}" "${CHECKPOINT}" "true"
bash ./build.sh "${PLATFORM}" "${SB_IMAGE}" "${CHECKPOINT}"

# run install script
curl -sL "https://raw.githubusercontent.com/Jigsaw-Code/outline-server/master/src/server_manager/install_scripts/install_server.sh" | sed '/local MACHINE_TYPE/,/fi/{d}' | bash
Expand Down Expand Up @@ -101,7 +118,7 @@ Also, the build script which named `/build.sh` will clone the Outline-Server rep
Other files which created by HoJeong Go (a.k.a Seia-Soto) has been licensed with [MIT License](./LICENSE).

```
MIT License Copyright 2022 HoJeong Go
MIT License Copyright 2022-2023 HoJeong Go
Permission is hereby granted, free of
charge, to any person obtaining a copy of this software and associated
Expand Down
59 changes: 25 additions & 34 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@ set -x
Usage:
./build.sh $arch $tag $checkpoint $use_legacy_install
./build.sh $arch $tag $checkpoint
-- Arguments:
$arch {string} The arch to build, using docker platform style
$tag {string} The docker tag to use while building the image
$checkpoint {string} The git branch or tag to checkout on Jigsaw-Code/Outline-Server
$use_legacy_install {boolean} Set as true to build recent versions of outline-server using Node.JS v16 (likely on master branch)
-- Environments:
$AB_LEAVE_BASE_DIRECTORY {any} If it is not empty string, script will not clean working directory
About:
This script builds Outline-Server docker image
This script builds Outline-Server docker buildx image
with specific arch by downloading compatible third_party
automatically.
'
Expand All @@ -34,7 +39,6 @@ TMP=$(mktemp -d)
ARCH=${1}
TAG=${2}
CHECKPOINT=${3}
USE_LEGACY_INSTALL=${4}

export DOCKER_PLATFORMS="${ARCH}"

Expand Down Expand Up @@ -68,16 +72,14 @@ unpack_archive_from_url() {
remap_arch() {
local ARCH="${1}" AMD64="${2:-amd64}" ARM64="${3:-arm64}" ARMv7="${4:-armv7}" ARMv6="${5:-armv6}"

[[ "${ARCH}" == *"amd64"* ]] && ARCH="${AMD64}"
[[ "${ARCH}" == *"arm64"* ]] && ARCH="${ARM64}"
[[ "${ARCH}" == *"v7"* ]] && ARCH="${ARMv7}"
[[ "${ARCH}" == *"v6"* ]] && ARCH="${ARMv6}"

echo "${ARCH}"
[[ "${ARCH}" == *"amd64"* ]] && echo "${AMD64}"
[[ "${ARCH}" == *"arm64"* ]] && echo "${ARM64}"
[[ "${ARCH}" == *"v7"* ]] && echo "${ARMv7}"
[[ "${ARCH}" == *"v6"* ]] && echo "${ARMv6}"
}

# Clone outline-server
git clone "https://github.com/${REPO_BASE}.git" "${NS_BASE}"
[[ ! -d "./outline-server" ]] && git clone "https://github.com/${REPO_BASE}.git" "${NS_BASE}"

# Go to repo and checkout to latest release
cd "${NS_BASE}"
Expand All @@ -98,44 +100,33 @@ do

unpack_archive_from_url "${NS_SSS}.${ARCH_SSS}" "${RES_SSS}" "0"

mkdir -p "third_parties/${C_ARCH}/outline-ss-server/linux"
mv "${TMP}/${NS_SSS}.${ARCH_SSS}/outline-ss-server" "third_parties/${C_ARCH}/outline-ss-server/linux"
mkdir -p "third_parties/${C_ARCH}/outline-ss-server"
mv "${TMP}/${NS_SSS}.${ARCH_SSS}/outline-ss-server" "third_parties/${C_ARCH}/outline-ss-server/"

# Download prometheus
ARCH_PROM="$(remap_arch "${C_ARCH}" amd64 arm64 armv7 armv6)"
RES_PROM="$(gh_release_asset_url_by_arch "${REPO_PROM}" "linux-${ARCH_PROM}")"

unpack_archive_from_url "${NS_PROM}.${ARCH_PROM}" "${RES_PROM}" "1"

mkdir -p "third_parties/${C_ARCH}/prometheus/linux"
mv "${TMP}/${NS_PROM}.${ARCH_PROM}/prometheus" "third_parties/${C_ARCH}/prometheus/linux"
mkdir -p "third_parties/${C_ARCH}/prometheus"
mv "${TMP}/${NS_PROM}.${ARCH_PROM}/prometheus" "third_parties/${C_ARCH}/prometheus/"
done

# Modify build environment
sed -i -e \
'/COPY third_party/s/^COPY third_party third_party/ARG TARGETPLATFORM\nCOPY third_parties\/\$\{TARGETPLATFORM\} third_party/' \
"src/shadowbox/docker/Dockerfile"
# Apply patches
for FILE in ../patches/*.patch; do
[[ -e "${FILE}" ]] || continue;
git apply "${FILE}";
done;

# Build docker-image
export SB_IMAGE="${TAG}"
export DOCKER_CONTENT_TRUST="0"

if [[ "${USE_LEGACY_INSTALL}" == "true" ]]; then
export NODE_IMAGE="node:12-alpine"
export NODE_IMAGE="node:16-alpine"

\cp -f "../extra/scripts/build.action.sh" "src/shadowbox/docker/build_action.sh"

npm run do shadowbox/docker/build
else
export NODE_IMAGE="node:16-alpine"

\cp -f "../extra/scripts/build.action.sh" "src/shadowbox/docker/build.action.sh"

npm run action shadowbox/docker/build
fi
npm run action shadowbox/docker/build

# Clean-up
cd ..

rm -rf "${TMP}"
rm -rf "${NS_BASE}"
[[ "${AB_LEAVE_BASE_DIRECTORY}" == "" ]] && rm -rf "${NS_BASE}"
40 changes: 0 additions & 40 deletions extra/scripts/build.action.sh

This file was deleted.

Loading

0 comments on commit f2287d5

Please sign in to comment.