Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge develop to main for release [EE-6941] #25

Closed
wants to merge 11 commits into from
6 changes: 5 additions & 1 deletion .github/workflows/dev.workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ jobs:
- name: checkout code
uses: actions/checkout@v2
# https://github.com/docker/setup-qemu-action
- name: "[preparation] set up golang"
uses: actions/[email protected]
with:
go-version-file: go.mod
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
# https://github.com/docker/setup-buildx-action
Expand All @@ -28,7 +32,7 @@ jobs:
driver-opts: image=moby/buildkit:v0.10.6
- uses: actions/setup-go@v3
with:
go-version: "1.19"
go-version: "1.22.5"
- name: login to docker hub
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin

Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/portainer-updater.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: portainer-updater

on:
workflow_dispatch:

jobs:
build_images:
runs-on: ubuntu-latest
steps:
- name: "placeholder"
run: echo "placeholder workflow"
25 changes: 18 additions & 7 deletions .github/workflows/prod.workflow.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
name: Build production docker image to Portainer

on:
push:
branches:
- main
workflow_dispatch:
inputs:
unpacker_version:
description: "portainer-updater version. e.g. 2.20.0"
required: true
release_branch:
description: "release branch. e.g. release/2.20"
required: true

jobs:
release:
Expand All @@ -12,18 +17,24 @@ jobs:
name: production
steps:
- name: checkout code
uses: actions/checkout@v2
uses: actions/[email protected]
with:
ref: ${{ github.event.inputs.release_branch }}

# https://github.com/docker/setup-qemu-action
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
uses: docker/[email protected]

# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3.0.0
with:
driver-opts: image=moby/buildkit:v0.10.6

- uses: actions/setup-go@v3
with:
go-version: "1.19"
go-version: "1.22.5"

- name: login to docker hub
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin

Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@ image: build
image_release: release
docker build -f $(dockerfile) -t $(image_release):$(tag) --build-arg GIT_COMMIT=$(GIT_COMMIT) .

tidy:
go mod tidy

clean:
rm -rf $(dist)/*
12 changes: 5 additions & 7 deletions build/windows/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ ARG GIT_COMMIT=unspecified
ARG OSVERSION
FROM --platform=linux/amd64 gcr.io/k8s-staging-e2e-test-images/windows-servercore-cache:1.0-linux-amd64-${OSVERSION} as core
FROM --platform=linux/amd64 alpine:3.13.0 as downloader
ENV GIT_VERSION 2.30.0
ENV GIT_PATCH_VERSION 2


ENV GIT_VERSION 2.46.0
ENV GIT_PATCH_VERSION 1

RUN mkdir mingit/ \
&& wget https://github.com/git-for-windows/git/releases/download/v$GIT_VERSION.windows.$GIT_PATCH_VERSION/MinGit-$GIT_VERSION.$GIT_PATCH_VERSION-busybox-64-bit.zip \
&& unzip MinGit-$GIT_VERSION.$GIT_PATCH_VERSION-busybox-64-bit.zip -d mingit/
&& wget https://github.com/git-for-windows/git/releases/download/v$GIT_VERSION.windows.$GIT_PATCH_VERSION/MinGit-$GIT_VERSION-busybox-64-bit.zip \
&& unzip MinGit-$GIT_VERSION-busybox-64-bit.zip -d mingit/

FROM mcr.microsoft.com/windows/nanoserver:${OSVERSION}
ENV PATH "C:\mingit\cmd;C:\app;C:\Windows\system32;C:\Windows;"
Expand All @@ -22,4 +20,4 @@ USER ContainerAdministrator
LABEL git_commit=$GIT_COMMIT

COPY dist /app/
ENTRYPOINT ["C:/app/portainer-updater.exe"]
ENTRYPOINT ["C:/app/portainer-updater.exe"]
13 changes: 7 additions & 6 deletions dockerstandalone/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/client"
"github.com/pkg/errors"
Expand All @@ -24,7 +25,7 @@ func findByLabelFn(label string) queryFn {
filters.Add("status", "running")
filters.Add("label", label)

containers, err := dockerCli.ContainerList(ctx, types.ContainerListOptions{
containers, err := dockerCli.ContainerList(ctx, container.ListOptions{
Filters: filters,
})
if err != nil {
Expand All @@ -50,7 +51,7 @@ func findByImageFn(possibleImagePrefixes ...string) queryFn {

// not using the ancestor filter because it looks for latest tag

containers, err := dockerCli.ContainerList(ctx, types.ContainerListOptions{
containers, err := dockerCli.ContainerList(ctx, container.ListOptions{
Filters: filters,
})
if err != nil {
Expand All @@ -75,15 +76,15 @@ func findByLogsFn(log string) queryFn {
filters := filters.NewArgs()
filters.Add("status", "running")

containers, err := dockerCli.ContainerList(ctx, types.ContainerListOptions{
containers, err := dockerCli.ContainerList(ctx, container.ListOptions{
Filters: filters,
})
if err != nil {
return nil, errors.WithMessage(err, "unable to list containers")
}

for _, container := range containers {
logs, err := dockerCli.ContainerLogs(ctx, container.ID, types.ContainerLogsOptions{
for _, c := range containers {
logs, err := dockerCli.ContainerLogs(ctx, c.ID, container.LogsOptions{
ShowStdout: true,
ShowStderr: true,
})
Expand All @@ -95,7 +96,7 @@ func findByLogsFn(log string) queryFn {

for scanner.Scan() {
if strings.Contains(scanner.Text(), log) {
return &container, nil
return &c, nil
}
}

Expand Down
18 changes: 10 additions & 8 deletions dockerstandalone/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import (

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/api/types/registry"
"github.com/docker/docker/client"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -123,7 +125,7 @@ func cleanupContainerAndError(ctx context.Context, dockerCli *client.Client, old
Msg("An error occurred during the update process - removing newly created container")

// should restart old container
err := dockerCli.ContainerStart(ctx, oldContainerId, types.ContainerStartOptions{})
err := dockerCli.ContainerStart(ctx, oldContainerId, container.StartOptions{})
if err != nil {
log.Err(err).
Str("containerId", oldContainerId).
Expand All @@ -133,7 +135,7 @@ func cleanupContainerAndError(ctx context.Context, dockerCli *client.Client, old
if newContainerID != "" {
printLogsToStdout(ctx, dockerCli, newContainerID)

err = dockerCli.ContainerRemove(ctx, newContainerID, types.ContainerRemoveOptions{Force: true})
err = dockerCli.ContainerRemove(ctx, newContainerID, container.RemoveOptions{Force: true})
if err != nil {
log.Err(err).
Msg("Unable to remove temporary container, please remove it manually")
Expand All @@ -156,11 +158,11 @@ func pullImage(ctx context.Context, dockerCli *client.Client, imageName string)
return false, nil
}

imagePullOptions := types.ImagePullOptions{}
imagePullOptions := image.PullOptions{}
if os.Getenv("REGISTRY_USED") != "" {
// Authenticate to the private registry
// ref@https://docs.docker.com/engine/api/sdk/examples/#pull-an-image-with-authentication
authConfig := types.AuthConfig{
authConfig := registry.AuthConfig{
Username: os.Getenv("REGISTRY_USERNAME"),
Password: os.Getenv("REGISTRY_PASSWORD"),
}
Expand Down Expand Up @@ -247,7 +249,7 @@ func tryRemoveOldContainer(ctx context.Context, dockerCli *client.Client, oldCon
Msg("Removing old container")

// remove old container
err := dockerCli.ContainerRemove(ctx, oldContainerId, types.ContainerRemoveOptions{Force: true})
err := dockerCli.ContainerRemove(ctx, oldContainerId, container.RemoveOptions{Force: true})
if err != nil {
log.Warn().Err(err).Msg("Unable to remove old container")
}
Expand Down Expand Up @@ -324,12 +326,12 @@ func startContainer(ctx context.Context, dockerCli *client.Client, oldContainerI
Str("containerId", newContainerID).
Msg("Starting new container")

err := dockerCli.ContainerStop(ctx, oldContainerID, nil)
err := dockerCli.ContainerStop(ctx, oldContainerID, container.StopOptions{})
if err != nil {
return errors.WithMessage(err, "Unable to stop old container")
}

err = dockerCli.ContainerStart(ctx, newContainerID, types.ContainerStartOptions{})
err = dockerCli.ContainerStart(ctx, newContainerID, container.StartOptions{})
if err != nil {
return errors.WithMessage(err, "Unable to start new container")
}
Expand Down Expand Up @@ -371,7 +373,7 @@ func printLogsToStdout(ctx context.Context, dockerCli *client.Client, containerI
Str("containerId", containerID).
Msg("Printing container logs to stdout")

reader, err := dockerCli.ContainerLogs(ctx, containerID, types.ContainerLogsOptions{ShowStdout: true, ShowStderr: true})
reader, err := dockerCli.ContainerLogs(ctx, containerID, container.LogsOptions{ShowStdout: true, ShowStderr: true})
if err != nil {
log.Error().Err(err).Msg("Unable to get container logs")
return
Expand Down
78 changes: 49 additions & 29 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,63 +1,83 @@
module github.com/portainer/portainer-updater

go 1.19
go 1.22.7

require (
github.com/Masterminds/semver v1.5.0
github.com/alecthomas/kong v0.5.0
github.com/docker/docker v20.10.14+incompatible
github.com/docker/docker v26.1.5+incompatible
github.com/hashicorp/nomad/api v0.0.0-20221020074335-1c9b4e398dd2
github.com/pkg/errors v0.9.1
github.com/rs/zerolog v1.28.0
k8s.io/api v0.22.5
k8s.io/apimachinery v0.22.5
k8s.io/client-go v0.22.5
k8s.io/api v0.26.2
k8s.io/apimachinery v0.26.2
k8s.io/client-go v0.26.2
)

require (
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/containerd/containerd v1.6.2 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/distribution v2.8.1+incompatible // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/go-logr/logr v1.2.2 // indirect
github.com/emicklei/go-restful/v3 v3.10.1 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/googleapis/gnostic v0.5.5 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/hashicorp/cronexpr v1.1.1 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.2 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
golang.org/x/net v0.0.0-20220407224826-aac1ed45d8e3 // indirect
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f // indirect
golang.org/x/sys v0.0.0-20220408201424-a24fb2fb8a0f // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220407144326-9054f6ed7bac // indirect
google.golang.org/grpc v1.45.0 // indirect
google.golang.org/protobuf v1.28.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.50.0 // indirect
go.opentelemetry.io/otel v1.25.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0 // indirect
go.opentelemetry.io/otel/metric v1.25.0 // indirect
go.opentelemetry.io/otel/sdk v1.19.0 // indirect
go.opentelemetry.io/otel/trace v1.25.0 // indirect
golang.org/x/mod v0.11.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/oauth2 v0.17.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/term v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
golang.org/x/tools v0.10.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/klog/v2 v2.30.0 // indirect
k8s.io/utils v0.0.0-20210930125809-cb0fa318a74b // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.1.2 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
gotest.tools/v3 v3.0.3 // indirect
k8s.io/klog/v2 v2.90.1 // indirect
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5 // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
Loading
Loading