Skip to content

Commit

Permalink
ADD: private apt repo in CI pipline
Browse files Browse the repository at this point in the history
  • Loading branch information
mc256 committed Oct 13, 2022
1 parent 9e79156 commit bfbb3fe
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 13 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/debian-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ jobs:
- name: Check out repository code
uses: actions/checkout@v3
- name: Build deb package
env:
APT_UPLOAD_AUTH: ${{ secrets.APT_UPLOAD_AUTH }}
run: |
sudo apt update -y
sudo apt upgrade -y
sudo apt install net-tools
docker run --privileged --rm tonistiigi/binfmt --install all
docker build -t helper:latest -f ./.github/.helper/Dockerfile ./.github/.helper/
docker run -d --hostname helper --expose 8080 --env AUTH=$BUILDAUTH --name helper -v "$(pwd)"/sandbox:/app/upload:rw helper:latest
docker run -d --hostname helper --expose 8080 --name helper -v "$(pwd)"/sandbox:/app/upload:rw helper:latest
export UPLOAD_URL=http://`docker inspect helper | grep "IPAddress" | grep -o -E '[0-9.]+' | head -n 1`:8080/
make docker-buildx-multi-arch
- name: Release
Expand Down
40 changes: 30 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ create-deb-package: change-version-number build-starlight-grpc build-ctr-starlig
.PHONY: create-deb-package.amd64
create-deb-package.amd64: create-deb-package

.PHONY: upload-deb-package.amd64
upload-deb-package.amd64:
curl --form uploadfile='@./sandbox/starlight-snapshotter_$(VERSIONNUMBER)_amd64.deb' $(UPLOAD_URL)

.PHONY: create-deb-package.armv6l
create-deb-package.armv6l: change-version-number build-starlight-grpc build-ctr-starlight generate-changelog
Expand All @@ -103,10 +100,6 @@ create-deb-package.armv6l: change-version-number build-starlight-grpc build-ctr-
dh_builddeb
dpkg-deb --info ./sandbox/starlight-snapshotter_$(VERSIONNUMBER)_armhf.deb

.PHONY: upload-deb-package.armv6l
upload-deb-package.armv6l:
curl --form uploadfile='@./sandbox/starlight-snapshotter_$(VERSIONNUMBER)_armhf.deb' $(UPLOAD_URL)

.PHONY: create-deb-package.arm64
create-deb-package.arm64: change-version-number build-starlight-grpc build-ctr-starlight generate-changelog
mkdir -p ./sandbox/starlight-snapshotter-$(VERSIONNUMBER)-$(COMPILEDATE)/ 2>/dev/null | true
Expand All @@ -124,16 +117,43 @@ create-deb-package.arm64: change-version-number build-starlight-grpc build-ctr-s
dh_builddeb
dpkg-deb --info ./sandbox/starlight-snapshotter_$(VERSIONNUMBER)_arm64.deb


.PHONY: upload-deb-package.amd64
upload-deb-package.amd64:
curl --form uploadfile='@./sandbox/starlight-snapshotter_$(VERSIONNUMBER)_amd64.deb' $(UPLOAD_URL)
curl -X POST -u $(APT_UPLOAD_AUTH) -F starlight-snapshotter_$(VERSIONNUMBER)_amd64.deb='@./sandbox/starlight-snapshotter_$(VERSIONNUMBER)_amd64.deb' https://repo.yuri.moe/api/files/starlight-snapshotter

.PHONY: upload-deb-package.armv6l
upload-deb-package.armv6l:
curl --form uploadfile='@./sandbox/starlight-snapshotter_$(VERSIONNUMBER)_armhf.deb' $(UPLOAD_URL)
curl -X POST -u $(APT_UPLOAD_AUTH) -F starlight-snapshotter_$(VERSIONNUMBER)_armhf.deb='@./sandbox/starlight-snapshotter_$(VERSIONNUMBER)_armhf.deb' https://repo.yuri.moe/api/files/starlight-snapshotter

.PHONY: upload-deb-package.amd64
upload-deb-package.arm64:
curl --form uploadfile='@./sandbox/starlight-snapshotter_$(VERSIONNUMBER)_arm64.deb' $(UPLOAD_URL)
curl -X POST -u $(APT_UPLOAD_AUTH) -F starlight-snapshotter_$(VERSIONNUMBER)_arm64.deb='@./sandbox/starlight-snapshotter_$(VERSIONNUMBER)_arm64.deb' https://repo.yuri.moe/api/files/starlight-snapshotter

######################################################################
.PHONY: docker-buildx-multi-arch
docker-buildx-multi-arch:
docker buildx build --platform linux/amd64 --build-arg ARCH=amd64 --build-arg UPLOAD_URL=$(UPLOAD_URL) -f ./demo/deb-package/Dockerfile .
docker buildx build --platform linux/arm/v7 --build-arg ARCH=armv6l --build-arg UPLOAD_URL=$(UPLOAD_URL) -f ./demo/deb-package/Dockerfile .
docker buildx build --platform linux/arm64/v8 --build-arg ARCH=arm64 --build-arg UPLOAD_URL=$(UPLOAD_URL) -f ./demo/deb-package/Dockerfile .
docker buildx build \
--platform linux/amd64 \
--build-arg ARCH=amd64 \
--build-arg UPLOAD_URL=$(UPLOAD_URL) \
--build-arg APT_UPLOAD_AUTH=$(APT_UPLOAD_AUTH) \
-f ./demo/deb-package/Dockerfile .
docker buildx build \
--platform linux/arm/v7 \
--build-arg ARCH=armv6l \
--build-arg UPLOAD_URL=$(UPLOAD_URL) \
--build-arg APT_UPLOAD_AUTH=$(APT_UPLOAD_AUTH) \
-f ./demo/deb-package/Dockerfile .
docker buildx build \
--platform linux/arm64/v8 \
--build-arg ARCH=arm64 \
--build-arg UPLOAD_URL=$(UPLOAD_URL) \
--build-arg APT_UPLOAD_AUTH=$(APT_UPLOAD_AUTH) \
-f ./demo/deb-package/Dockerfile .

######################################################################
# Clean
Expand Down
12 changes: 11 additions & 1 deletion cmd/ctr-starlight/report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ package report
import (
"context"
"github.com/containerd/containerd/log"

"github.com/mc256/starlight/fs"
"github.com/mc256/starlight/grpc"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)

Expand All @@ -46,6 +46,16 @@ func Action(c *cli.Context) error {
"please set your own starlight server using environment variable STARLIGHT_PROXY or --server flag")
}

if server == "" {
log.G(ctx).Fatal("no starlight proxy server address provided")
return nil
}

log.G(ctx).WithFields(logrus.Fields{
"server": server,
"protocol": protocol,
}).Info("uploading data to starlight proxy server")

proxy := grpc.NewStarlightProxy(ctx, protocol, c.String("server"))
if err := proxy.Report(tc.ToJSONBuffer()); err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions demo/deb-package/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ WORKDIR /go/src/app

ARG ARCH=amd64
ARG UPLOAD_URL=http://127.0.0.1:35001/
ARG APT_UPLOAD_AUTH=XXXX

ENV GO111MODULE=on
ENV REGISTRY=registry2
Expand Down
16 changes: 15 additions & 1 deletion grpc/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,21 @@ func (a *StarlightProxy) Report(buf []byte) error {
if err != nil {
log.G(a.ctx).WithError(err).Error("response body error")
}
fmt.Println(string(resBuf[:]))

if resp.StatusCode == 200 {
log.G(a.ctx).WithFields(logrus.Fields{
"code": fmt.Sprintf("%d"),
"message": strings.TrimSpace(string(resBuf[:])),
"version": resp.Header.Get("Starlight-Version"),
}).Info("upload finished")
} else {
log.G(a.ctx).WithFields(logrus.Fields{
"code": fmt.Sprintf("%d"),
"message": strings.TrimSpace(string(resBuf[:])),
"version": resp.Header.Get("Starlight-Version"),
}).Warn("upload finished")
}

return nil
}

Expand Down

0 comments on commit bfbb3fe

Please sign in to comment.