Skip to content

Commit

Permalink
add more github actions (#19)
Browse files Browse the repository at this point in the history
add pre-release
  • Loading branch information
woodgear authored Aug 13, 2024
1 parent 24496d8 commit 34febbe
Show file tree
Hide file tree
Showing 12 changed files with 223 additions and 76 deletions.
18 changes: 15 additions & 3 deletions .github/workflows/build-openresty.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ jobs:
build-openresty:
name: Build Openresty
runs-on: ubuntu-22.04
strategy:
matrix:
platform:
- linux/amd64
# - linux/arm64
steps:
- uses: actions/checkout@v4
- name: Configure Git
Expand All @@ -24,19 +29,26 @@ jobs:
git config user.email "[email protected]"
- uses: docker/setup-buildx-action@v3
- name: build
env:
MATRIX_PLATFORM: "${{ matrix.platform }}"
run: |
./scripts/run-like-github-actions.sh build-nginx
platform=$(echo "$MATRIX_PLATFORM" | sed 's|/|-|g')
echo "artifactPath=./alb-nginx-base-$platform.tar" >> $GITHUB_ENV
echo "artifactName=alb-nginx-base-$platform" >> $GITHUB_ENV
- name: Upload alb-nginx-base images to artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: alb-nginx-base
path: alb-nginx-base.tar
name: ${{ env.artifactName }}
path: ${{ env.artifactPath }}
- name: release
if: ${{ inputs.do_release }}
env:
RELEASE_ME: "${{ github.event.inputs.do_release == 'true' }}"
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
DOCKER_CLI_EXPERIMENTAL: enabled
run: |
env
./scripts/run-like-github-actions.sh release-nginx
101 changes: 83 additions & 18 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ name: build-alb-images-and-chart
on:
workflow_dispatch:
inputs:
skip_test:
type: boolean
description: skil test
required: false
default: false
do_release:
type: boolean
description: do release
Expand Down Expand Up @@ -34,6 +39,11 @@ jobs:
build-alb:
name: Build alb
runs-on: ubuntu-22.04
strategy:
matrix:
platform:
- linux/amd64
# - linux/arm64
steps:
- uses: actions/checkout@v4
- name: Configure Git
Expand All @@ -47,44 +57,99 @@ jobs:
version-file: ./deploy/chart/alb/Chart.yaml
version-file-extraction-pattern: 'version: v([0-9]*\.[0-9]*\.[0-9]*)'
- uses: docker/setup-buildx-action@v3
- uses: azure/setup-helm@v3
with:
version: '${{ env.HELM_VERSION }}'
- name: test alb go
run: |
set -x
./scripts/run-like-github-actions.sh test-alb-go
- name: build
env:
RELEASE_ME: "${{ github.event.inputs.do_release == 'true' }}"
MATRIX_PLATFORM: "${{matrix.platform }}"
run: |
set -x
./scripts/run-like-github-actions.sh build-alb
platform=$(echo "$MATRIX_PLATFORM" | sed 's|/|-|g')
echo "artifactPath=./alb-$platform.tar" >> $GITHUB_ENV
echo "artifactName=alb-$platform" >> $GITHUB_ENV
- name: Upload alb images to artifact
uses: actions/upload-artifact@v3
with:
name: alb
path: alb.tar
- name: Upload chart's to artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: alb-chart
path: alauda-alb2.tgz
name: ${{ env.artifactName }}
path: ${{ env.artifactPath }}
- name: test alb go
if: ${{ (matrix.platform == 'linux/amd64' ) && (!inputs.skip_test) }}
env:
MATRIX_PLATFORM: "${{ matrix.platform }}"
run: |
set -x
echo "FROM --platform=\${{ matrix.platform }} | $MATRIX_PLATFORM "
./scripts/run-like-github-actions.sh test-alb-go
- name: test alb nginx
if: ${{ (matrix.platform == 'linux/amd64' ) && (!inputs.skip_test) }}
env:
MATRIX_PLATFORM: "${{matrix.platform }}"
run: |
set -x
./scripts/run-like-github-actions.sh test-alb-nginx
release-alb:
name: Release alb
runs-on: ubuntu-22.04
needs: [build-alb]
steps:
- uses: actions/checkout@v4
- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"
- name: version # it will set the CURRENT_VERSION env
uses: HardNorth/[email protected]
with:
version-source: file
version-file: ./deploy/chart/alb/Chart.yaml
version-file-extraction-pattern: 'version: v([0-9]*\.[0-9]*\.[0-9]*)'
- name: cr
uses: helm/[email protected]
with:
install_only: true
- name: release
if: ${{ inputs.do_release }}
- uses: azure/setup-helm@v3
with:
version: '${{ env.HELM_VERSION }}'
- uses: actions/download-artifact@master # TODO download arm artifact
with:
name: alb-linux-amd64
- name: show artifact
run: |
ls -l
- name: set release type
env:
RELEASE_ME: "${{ github.event.inputs.do_release == 'true' }}"
run: |
branch=$(echo "${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" | sed 's|/|-|g')
echo "branch is $branch"
if [[ "$RELEASE_ME" == "false" ]] && [[ "$branch" == "master" ]] ;then
echo "in master we still want to a pre-release"
echo "RELEASE_TYPE=pre-release" >> $GITHUB_ENV
exit
fi
if [[ "$RELEASE_ME" == "true" ]] ;then
echo "release it"
echo "RELEASE_TYPE=release" >> $GITHUB_ENV
exit
fi
echo "RELEASE_TYPE=no-release" >> $GITHUB_ENV
echo "not release"
- name: gen alb chart
run: |
echo "gen alb chart"
env
./scripts/run-like-github-actions.sh gen-chart-artifact
- uses: actions/upload-artifact@v4
with:
name: alb-chart
path: alauda-alb2.tgz
- name: release
if: ${{ env.RELEASE_TYPE != 'no-release' }}
env:
GH_TOKEN: ${{ github.token }}
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
DOCKER_CLI_EXPERIMENTAL: enabled
run: |
./scripts/run-like-github-actions.sh release-alb
./scripts/run-like-github-actions.sh release-alb
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ RUN go build -buildmode=pie -ldflags '-w -s -linkmode=external -extldflags=-Wl,-
RUN ldd /out/albctl || true

FROM ${OPENRESTY_BASE} AS base
ENV ALB_ONLINE =$ALB_ONLINE
ARG ALB_ONLINE
ENV ALB_ONLINE=${ALB_ONLINE}
WORKDIR /tmp/
COPY ./template/actions /tmp/
# install our lua dependency
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories && \
RUN env && sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories && \
apk add --no-cache --virtual .builddeps luarocks5.1 lua5.1 lua5.1-dev bash perl curl build-base make unzip && \
cp /usr/bin/luarocks-5.1 /usr/bin/luarocks && \
ls /tmp && bash /tmp/alb-nginx-install-deps.sh /usr/local/openresty && \
ls /tmp && echo "\n\n alb-nginx-install-deps.sh \n\n" && bash /tmp/alb-nginx-install-deps.sh /usr/local/openresty && \
apk del .builddeps build-base make unzip && cd / && rm -rf /tmp && rm /usr/bin/luarocks && rm /usr/bin/nc

# tweak files
Expand Down
3 changes: 2 additions & 1 deletion scripts/alb-github-actions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ function alb-gh-wk-build-and-relase-nginx() (
function alb-gh-wk-build-and-relase-alb() (
local branch=${1-$(git rev-parse --abbrev-ref HEAD)}
local relase=${2-false}
gh workflow run build.yaml --ref $branch -f do_release=$relase
local skip_test=${3-false}
gh workflow run build.yaml --ref $branch -f do_release=$relase -f skip_test=$skip_test
)
47 changes: 38 additions & 9 deletions scripts/alb-test-actions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,49 @@ function alb-go-unit-test() {
}

function alb-envtest-install() {
curl --progress-bar -sSLo envtest-bins.tar.gz $(_switch_url "https://go.kubebuilder.io/test-tools/1.24.2/$(go env GOOS)/$(go env GOARCH)" "http://prod-minio.alauda.cn:80/acp/envtest-bins.1.24.2.tar.gz")
curl --progress-bar -sSLo envtest-bins.tar.gz $(__at_resolve_url envtest)
mkdir -p /usr/local/kubebuilder
tar -C /usr/local/kubebuilder --strip-components=1 -zvxf envtest-bins.tar.gz
rm envtest-bins.tar.gz
ls /usr/local/kubebuilder
/usr/local/kubebuilder/bin/kube-apiserver --version
}

function _switch_url() {
if [[ -n "$ALB_ONLINE" ]]; then
echo $1
else
echo $2
function __at_resolve_url() {
local name="$1"
local arch=$(uname -m)

local envtest_url="https://go.kubebuilder.io/test-tools/1.24.2/$(go env GOOS)/$(go env GOARCH)"
local cfg=$(
cat <<EOF
{
"kubectl_x86_64_online": "https://dl.k8s.io/v1.24.1/kubernetes-client-linux-amd64.tar.gz",
"helm_x86_64_online": "https://mirrors.huaweicloud.com/helm/v3.9.3/helm-v3.9.3-linux-amd64.tar.gz",
"golangcli_x86_64_online": "https://github.com/golangci/golangci-lint/releases/download/v1.59.1/golangci-lint-1.59.1-illumos-amd64.tar.gz",
"envtest_x86_64_online": "$envtest_url",
"kubectl_arm_online": "https://get.helm.sh/helm-v3.7.0-linux-amd64.tar.gz",
"helm_arm_online": "https://get.helm.sh/helm-v3.7.0-linux-amd64.tar.gz",
"golangcli_arm_online": "https://get.helm.sh/helm-v3.7.0-linux-amd64.tar.gz",
"envtest_arm_online": "$envtest_url",
"kubectl_x86_64_offline": "http://prod-minio.alauda.cn/acp/ci/alb/build/kubernetes-client-linux-amd64.tar.gz",
"helm_x86_64_offline": "http://prod-minio.alauda.cn/acp/ci/alb/build/helm-v3.9.3-linux-amd64.tar.gz",
"golangcli_x86_64_offline": "http://prod-minio.alauda.cn/acp/ci/alb/build/golangci-lint-1.59.1-illumos-amd64.tar.gz",
"envtest_x86_64_offline": "http://prod-minio.alauda.cn:80/acp/envtest-bins.1.24.2.tar.gz"
}
EOF
)
local mode="offline"
if [[ "$ALB_ONLINE" == "true" ]]; then
mode="online"
fi
local url=$(echo "$cfg" | jq -r ".${name}_${arch}_${mode}")
if [[ -z "$url" ]]; then
echo "not found $name $arch $mode"
return 1
fi
echo $url
}

function alb-install-golang-test-dependency() {
Expand All @@ -117,7 +146,7 @@ function alb-install-golang-test-dependency() {
if [ -f "$(which helm)" ]; then echo "dependency already installed" return; else echo "dependency not installed. install it"; fi

# rm -rf kubernetes-client-linux-amd64.tar.gz && wget &&
local kubectl_url=$(_switch_url https://dl.k8s.io/v1.24.1/kubernetes-client-linux-amd64.tar.gz http://prod-minio.alauda.cn/acp/ci/alb/build/kubernetes-client-linux-amd64.tar.gz)
local kubectl_url=$(__at_resolve_url kubectl)

wget $kubectl_url
tar -zxvf kubernetes-client-linux-amd64.tar.gz
Expand All @@ -129,13 +158,13 @@ function alb-install-golang-test-dependency() {
which kubectl

echo "install helm"
local helm_url=$(_switch_url https://mirrors.huaweicloud.com/helm/v3.9.3/helm-v3.9.3-linux-amd64.tar.gz http://prod-minio.alauda.cn/acp/ci/alb/build/helm-v3.9.3-linux-amd64.tar.gz)
local helm_url=$(__at_resolve_url helm)
wget $helm_url
tar -zxvf helm-v3.9.3-linux-amd64.tar.gz && chmod +x ./linux-amd64/helm && mv ./linux-amd64/helm /usr/local/bin/helm && rm -rf ./linux-amd64 && rm ./helm-v3.9.3-linux-amd64.tar.gz

helm version
# url -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.55.2
local golangci_lint=$(_switch_url "https://github.com/golangci/golangci-lint/releases/download/v1.59.1/golangci-lint-1.59.1-illumos-amd64.tar.gz" "http://prod-minio.alauda.cn/acp/ci/alb/build/golangci-lint-1.59.1-illumos-amd64.tar.gz")
local golangci_lint=$(__at_resolve_url golangcli)
wget $golangci_lint
tar -zxvf ./golangci-lint-1.59.1-illumos-amd64.tar.gz
chmod +x ./golangci-lint-1.59.1-illumos-amd64/golangci-lint && mv ./golangci-lint-1.59.1-illumos-amd64/golangci-lint /usr/local/bin/golangci-lint
Expand Down
2 changes: 1 addition & 1 deletion scripts/go-test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
pwd
sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
apk add bash
apk add bash curl jq
bash -c 'ALB=$PWD;source ./scripts/alb-dev-actions.sh;alb-test-all-in-ci-golang'
2 changes: 1 addition & 1 deletion scripts/nginx-test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
pwd
sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
apk add bash
apk add bash curl jq
bash -c 'ALB=$PWD;source ./template/actions/alb-nginx.sh;alb-test-all-in-ci-nginx'
6 changes: 4 additions & 2 deletions scripts/run-like-ci-go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ if [ -n "$USE_PROXY" ]; then
proxy="--network=host -e http_proxy=$HTTP_PROXY -e https_proxy=$HTTPS_PROXY "
fi
base=${1-$(cat ./Dockerfile | grep GO_BUILD_BASE | awk -F = '{print $2}')}
echo "$base"
docker run $proxy -v $PWD:/acp-alb-test -e ALB_ONLINE=$ALB_ONLINE -t $base sh -c "cd /acp-alb-test ;/acp-alb-test/scripts/go-test.sh"
echo "base $base"
platform=${MATRIX_PLATFORM:-linux/amd64}
echo "platform -- $platform --"
docker run $proxy -v $PWD:/acp-alb-test --platform $platform -e ALB_ONLINE=$ALB_ONLINE -t $base sh -c "cd /acp-alb-test ;/acp-alb-test/scripts/go-test.sh"
5 changes: 4 additions & 1 deletion scripts/run-like-ci-nginx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ if [ -n "$1" ]; then
image="$1"
fi
# image=alb-nginx:test
docker run --user root --network=host -v $PWD:/acp-alb-test -t $image sh -c 'cd /acp-alb-test ;/acp-alb-test/scripts/nginx-test.sh'

platform=${MATRIX_PLATFORM:-linux/amd64}
echo "platform $platform"
docker run --user root --network=host --platform $platform -v $PWD:/acp-alb-test -t $image sh -c 'cd /acp-alb-test ;/acp-alb-test/scripts/nginx-test.sh'
Loading

0 comments on commit 34febbe

Please sign in to comment.