-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add downloading progress for app image pull
- Loading branch information
Showing
41 changed files
with
2,219 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: Publish to Dockerhub | ||
name: Publish app-service to Dockerhub | ||
|
||
on: | ||
workflow_dispatch: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Publish image-service to Dockerhub | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
tags: | ||
description: 'Release Tags' | ||
|
||
jobs: | ||
update_dockerhub: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out the repo | ||
uses: actions/checkout@v3 | ||
|
||
- name: Log in to Docker Hub | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_PASS }} | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v3 | ||
with: | ||
push: true | ||
tags: beclab/image-service:${{ github.event.inputs.tags }} | ||
file: Dockerfile.image | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Build the manager binary | ||
FROM golang:1.18 as builder | ||
|
||
WORKDIR /workspace | ||
# Copy the Go Modules manifests | ||
COPY go.mod bytetrade.io/web3os/app-service/go.mod | ||
COPY go.sum bytetrade.io/web3os/app-service/go.sum | ||
|
||
RUN cd bytetrade.io/web3os/app-service && \ | ||
go mod download | ||
|
||
# Copy the go source | ||
COPY cmd/ bytetrade.io/web3os/app-service/cmd/ | ||
COPY api/ bytetrade.io/web3os/app-service/api/ | ||
COPY controllers/ bytetrade.io/web3os/app-service/controllers/ | ||
COPY pkg/ bytetrade.io/web3os/app-service/pkg/ | ||
|
||
# Build | ||
RUN cd bytetrade.io/web3os/app-service && \ | ||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -a -o image-service cmd/image-service/main.go | ||
|
||
# Use distroless as minimal base image to package the manager binary | ||
# Refer to https://github.com/GoogleContainerTools/distroless for more details | ||
FROM gcr.io/distroless/static:debug | ||
WORKDIR / | ||
COPY --from=builder /workspace/bytetrade.io/web3os/app-service/image-service . | ||
|
||
ENTRYPOINT ["/image-service"] | ||
USER 65532:65532 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
//+genclient | ||
//+genclient:nonNamespaced | ||
//+kubebuilder:object:root=true | ||
//+kubebuilder:subresource:status | ||
//+kubebuilder:resource:scope=Cluster, shortName={im}, categories={all} | ||
//+kubebuilder:printcolumn:JSONPath=.spec.appName, name=application name, type=string | ||
//+kubebuilder:printcolumn:JSONPath=.spec.appNamespace, name=namespace, type=string | ||
//+kubebuilder:printcolumn:JSONPath=.status.state, name=state, type=string | ||
//+kubebuilder:printcolumn:JSONPath=.metadata.creationTimestamp, name=age, type=date | ||
//+k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object | ||
|
||
// ImageManager is the Schema for the image managers API | ||
type ImageManager struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec ImageManagerSpec `json:"spec,omitempty"` | ||
Status ImageManagerStatus `json:"status,omitempty"` | ||
} | ||
|
||
// ImageManagerStatus defines the observed state of ApplicationManager | ||
type ImageManagerStatus struct { | ||
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster | ||
// Important: Run "make" to regenerate code after modifying this file | ||
Conditions []ImageProgress `json:"conditions,omitempty"` | ||
Message string `json:"message,omitempty"` | ||
State string `json:"state"` | ||
UpdateTime *metav1.Time `json:"updateTime"` | ||
StatusTime *metav1.Time `json:"statusTime"` | ||
} | ||
|
||
// ImageManagerSpec defines the desired state of ImageManager | ||
type ImageManagerSpec struct { | ||
AppName string `json:"appName"` | ||
AppNamespace string `json:"appNamespace,omitempty"` | ||
AppOwner string `json:"appOwner,omitempty"` | ||
Refs []string `json:"refs"` | ||
} | ||
|
||
type ImageProgress struct { | ||
NodeName string `json:"nodeName"` | ||
ImageRef string `json:"imageRef"` | ||
Progress string `json:"progress"` | ||
} | ||
|
||
//+kubebuilder:object:root=true | ||
//+k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object | ||
|
||
// ImageManagerList contains a list of ApplicationManager | ||
type ImageManagerList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []ImageManager `json:"items"` | ||
} | ||
|
||
func init() { | ||
SchemeBuilder.Register(&ImageManager{}, &ImageManagerList{}) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package main | ||
|
||
import ( | ||
appv1alpha1 "bytetrade.io/web3os/app-service/api/app.bytetrade.io/v1alpha1" | ||
sysv1alpha1 "bytetrade.io/web3os/app-service/api/sys.bytetrade.io/v1alpha1" | ||
"bytetrade.io/web3os/app-service/controllers" | ||
"context" | ||
"go.uber.org/zap/zapcore" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
utilruntime "k8s.io/apimachinery/pkg/util/runtime" | ||
clientgoscheme "k8s.io/client-go/kubernetes/scheme" | ||
"os" | ||
"os/signal" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/healthz" | ||
"sigs.k8s.io/controller-runtime/pkg/log/zap" | ||
"syscall" | ||
) | ||
|
||
var ( | ||
scheme = runtime.NewScheme() | ||
imageLog = ctrl.Log.WithName("image") | ||
) | ||
|
||
func init() { | ||
utilruntime.Must(clientgoscheme.AddToScheme(scheme)) | ||
utilruntime.Must(appv1alpha1.AddToScheme(scheme)) | ||
utilruntime.Must(sysv1alpha1.AddToScheme(scheme)) | ||
//+kubebuilder:scaffold:scheme | ||
} | ||
|
||
var shutdownSignals = []os.Signal{os.Interrupt, syscall.SIGTERM} | ||
|
||
func main() { | ||
opts := zap.Options{ | ||
Development: true, | ||
TimeEncoder: zapcore.RFC3339TimeEncoder, | ||
} | ||
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts))) | ||
config := ctrl.GetConfigOrDie() | ||
mgr, err := ctrl.NewManager(config, ctrl.Options{ | ||
Scheme: scheme, | ||
MetricsBindAddress: ":8087", | ||
HealthProbeBindAddress: ":7081", | ||
LeaderElection: false, | ||
}) | ||
if err != nil { | ||
imageLog.Error(err, "Unable to start image manager") | ||
os.Exit(1) | ||
} | ||
|
||
if err = (&controllers.ImageManagerController{ | ||
Client: mgr.GetClient(), | ||
}).SetupWithManager(mgr); err != nil { | ||
imageLog.Error(err, "Unable to create image controller") | ||
os.Exit(1) | ||
} | ||
|
||
if err = mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil { | ||
imageLog.Error(err, "Unable to set up health check") | ||
os.Exit(1) | ||
} | ||
if err = mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil { | ||
imageLog.Error(err, "Unable to set up ready check") | ||
os.Exit(1) | ||
} | ||
|
||
ictx, cancelFunc := context.WithCancel(context.Background()) | ||
|
||
c := make(chan os.Signal, 2) | ||
signal.Notify(c, shutdownSignals...) | ||
go func() { | ||
select { | ||
case <-c: | ||
cancelFunc() | ||
<-c | ||
os.Exit(1) // second signal. Exit directly. | ||
|
||
} | ||
}() | ||
|
||
if err = mgr.Start(ictx); err != nil { | ||
cancelFunc() | ||
imageLog.Error(err, "Unable to running image manager") | ||
os.Exit(1) | ||
} | ||
cancelFunc() | ||
} |
Oops, something went wrong.