Skip to content
This repository has been archived by the owner on Oct 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #58 from docker/feature/add-bugsnag
Browse files Browse the repository at this point in the history
Add Bugsnag to report errors
  • Loading branch information
benja-M-1 authored Sep 15, 2022
2 parents e9f1c16 + e425f78 commit 37a42db
Show file tree
Hide file tree
Showing 28 changed files with 315 additions and 250 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/build-scan-push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ jobs:
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64
build-args: |
BUGSNAG_RELEASE_STAGE=""
BUGSNAG_APP_VERSION=""
secrets: |
BUGSNAG_API_KEY=""
- name: Run Trivy for all CVEs (non-blocking)
uses: aquasecurity/trivy-action@master
Expand Down Expand Up @@ -123,6 +128,7 @@ jobs:
org.opencontainers.image.title=Volumes Backup & Share
org.opencontainers.image.description=Back up, clone, restore, and share Docker volumes effortlessly.
org.opencontainers.image.vendor=Docker Inc.
- name: Docker Build and Push to Docker Hub
if: ${{ !github.event.pull_request.head.repo.fork }}
uses: docker/build-push-action@v2
Expand All @@ -133,6 +139,12 @@ jobs:
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64
build-args: |
BUGSNAG_RELEASE_STAGE=production
BUGSNAG_APP_VERSION=${{ github.event.release.tag_name }}
secrets: |
BUGSNAG_API_KEY=${{ secrets.BUGSNAG_API_KEY }}
# If PR, put image tags in the PR comments
# from https://github.com/marketplace/actions/create-or-update-comment
- name: Find comment for image tags
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/hadolint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ jobs:
- uses: hadolint/hadolint-action@v2.0.0
with:
dockerfile: Dockerfile
ignore: DL3048,DL3025
ignore: DL3048,DL3025,DL3018
28 changes: 26 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,18 @@ RUN --mount=type=cache,target=/usr/src/app/.npm \
npm ci
# install
COPY ui /ui
RUN npm run build
RUN --mount=type=secret,id=BUGSNAG_API_KEY \
REACT_APP_BUGSNAG_API_KEY=$(cat /run/secrets/BUGSNAG_API_KEY) \
npm run build

FROM alpine:3.16 as base
ARG CLI_VERSION=20.10.17
SHELL ["/bin/ash", "-eo", "pipefail", "-c"]
RUN apk update \
&& apk add --no-cache ca-certificates curl \
&& rm -rf /var/cache/apk/*
RUN curl -fL "https://download.docker.com/linux/static/stable/$(uname -m)/docker-${CLI_VERSION}.tgz" | tar zxf - --strip-components 1 docker/docker \
&& chmod +x /docker

FROM --platform=$BUILDPLATFORM golang:1.17-alpine AS docker-credentials-client-builder
ENV CGO_ENABLED=0
Expand All @@ -32,6 +43,13 @@ COPY client .
RUN make cross

FROM busybox:1.35.0

ARG BUGSNAG_RELEASE_STAGE="local"
ARG BUGSNAG_APP_VERSION="latest"

ENV BUGSNAG_RELEASE_STAGE=$BUGSNAG_RELEASE_STAGE
ENV BUGSNAG_APP_VERSION=$BUGSNAG_APP_VERSION

LABEL org.opencontainers.image.title="Volumes Backup & Share" \
org.opencontainers.image.description="Back up, clone, restore, and share Docker volumes effortlessly." \
org.opencontainers.image.vendor="Docker Inc." \
Expand Down Expand Up @@ -76,10 +94,16 @@ WORKDIR /
COPY docker-compose.yaml .
COPY metadata.json .
COPY icon.svg .
COPY --from=base /etc/ssl/certs /etc/ssl/certs
COPY --from=base /docker /usr/local/bin/docker
COPY --from=builder /backend/bin/service /
COPY --from=client-builder /ui/build ui
COPY --from=docker-credentials-client-builder output/dist ./host

RUN mkdir -p /vackup

CMD /service -socket /run/guest-services/ext.sock
RUN --mount=type=secret,id=BUGSNAG_API_KEY \
BUGSNAG_API_KEY=$(cat /run/secrets/BUGSNAG_API_KEY); \
echo "$BUGSNAG_API_KEY" > /tmp/bugsnag-api-key.txt

ENTRYPOINT ["/bin/sh", "-c", "BUGSNAG_API_KEY=$(cat /tmp/bugsnag-api-key.txt); rm -rf /tmp/bugsnag-api-key.txt; BUGSNAG_API_KEY=$BUGSNAG_API_KEY /service -socket /run/guest-services/ext.sock"]
14 changes: 11 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
IMAGE?=docker/volumes-backup-extension
TAG?=latest

BUILDER=buildx-multi-arch

export BUGSNAG_API_KEY?=
export BUGSNAG_RELEASE_STAGE?=local

INFO_COLOR = \033[0;36m
NO_COLOR = \033[m

build-extension: ## Build service image to be deployed as a desktop extension
docker buildx build --load --tag=$(IMAGE):$(TAG) .
docker buildx build \
--secret id=BUGSNAG_API_KEY \
--build-arg BUGSNAG_RELEASE_STAGE=$(BUGSNAG_RELEASE_STAGE) \
--build-arg BUGSNAG_APP_VERSION=$(TAG) \
--load \
--tag=$(IMAGE):$(TAG) \
.

install-extension: build-extension ## Install the extension
docker extension install $(IMAGE):$(TAG)
Expand All @@ -26,7 +34,7 @@ prepare-buildx: ## Create buildx builder for multi-arch build, if not exists
docker buildx inspect $(BUILDER) || docker buildx create --name=$(BUILDER) --driver=docker-container --driver-opt=network=host

push-extension: prepare-buildx ## Build & Upload extension image to hub. Do not push if tag already exists: make push-extension tag=0.1
docker pull $(IMAGE):$(TAG) && echo "Failure: Tag already exists" || docker buildx build --push --builder=$(BUILDER) --platform=linux/amd64,linux/arm64 --build-arg TAG=$(TAG) --tag=$(IMAGE):$(TAG) .
docker pull $(IMAGE):$(TAG) && echo "Failure: Tag already exists" || docker buildx build --secret id=BUGSNAG_API_KEY --build-arg BUGSNAG_RELEASE_STAGE=$(BUGSNAG_RELEASE_STAGE) --build-arg BUGSNAG_APP_VERSION=$(TAG) --push --builder=$(BUILDER) --platform=linux/amd64,linux/arm64 --build-arg TAG=$(TAG) --tag=$(IMAGE):$(TAG) .

help: ## Show this help
@echo Please specify a build target. The choices are:
Expand Down
1 change: 1 addition & 0 deletions ui/.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
PUBLIC_URL=.
BROWSER=none
REACT_APP_BUGSNAG_API_KEY=
4 changes: 4 additions & 0 deletions vm/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,20 @@ require (
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bugsnag/bugsnag-go/v2 v2.1.2 // indirect
github.com/bugsnag/panicwrap v1.3.4 // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
github.com/docker/docker-credential-helpers v0.6.4 // indirect
github.com/docker/go-metrics v0.0.1 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 // indirect
github.com/gofrs/uuid v4.0.0+incompatible // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.4.3 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect
github.com/labstack/gommon v0.3.1 // indirect
github.com/mattn/go-colorable v0.1.11 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
Expand Down
11 changes: 11 additions & 0 deletions vm/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bitly/go-simplejson v0.5.0/go.mod h1:cXHtHw4XUPsvGaxgjIAn8PhEWG9NfngEKAMDJEczWVA=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/bugsnag/bugsnag-go/v2 v2.1.2 h1:R5rgYn5w5LhVIere+n+Ah49pa4E1b3OP2bSwHtURmv8=
github.com/bugsnag/bugsnag-go/v2 v2.1.2/go.mod h1:mJCnw33SPVYPFTsAeSR/kpwuyvjTXrPK5w/XZfTUwMU=
github.com/bugsnag/panicwrap v1.3.4 h1:A6sXFtDGsgU/4BLf5JT0o5uYg3EeKgGx3Sfs+/uk3pU=
github.com/bugsnag/panicwrap v1.3.4/go.mod h1:D/8v3kj0zr8ZAKg1AQ6crr+5VwKN5eIywRkfhyM/+dE=
github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/creack/pty v1.1.11 h1:07n33Z8lZxZ2qwegKbObQohDhXDQxiMMz1NOUGYlesw=
Expand Down Expand Up @@ -45,6 +51,8 @@ github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gofrs/uuid v4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPhW6m+TnJw=
github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
Expand Down Expand Up @@ -75,13 +83,16 @@ github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/
github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 h1:iQTw/8FWTuc7uiaSepXwyf3o52HaUYcV+Tu66S3F5GA=
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
Expand Down
57 changes: 0 additions & 57 deletions vm/internal/backend/auth.go

This file was deleted.

2 changes: 2 additions & 0 deletions vm/internal/backend/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"
"time"

"github.com/bugsnag/bugsnag-go/v2"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"
Expand All @@ -24,6 +25,7 @@ func GetContainersForVolume(ctx context.Context, cli *client.Client, volumeName
})
if err != nil {
log.Error(err)
_ = bugsnag.Notify(err, ctx)
}

containerNames := make([]string, 0, len(containers))
Expand Down
6 changes: 4 additions & 2 deletions vm/internal/backend/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ package backend

import (
"context"
"github.com/bugsnag/bugsnag-go/v2"
"github.com/docker/docker/client"
"github.com/sirupsen/logrus"
"github.com/docker/volumes-backup-extension/internal/log"
)

func GetVolumeDriver(ctx context.Context, cli *client.Client, volumeName string) string {
resp, err := cli.VolumeInspect(ctx, volumeName)
if err != nil {
logrus.Error(err)
log.Error(err)
_ = bugsnag.Notify(err, ctx)
}

return resp.Driver
Expand Down
23 changes: 12 additions & 11 deletions vm/internal/backend/size.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,19 @@ type VolumeSize struct {
Human string
}

func GetVolumesSize(ctx context.Context, cli *client.Client, volumeName string) map[string]VolumeSize {
func GetVolumesSize(ctx context.Context, cli *client.Client, volumeName string) (map[string]VolumeSize, error) {
m := make(map[string]VolumeSize)

// Ensure the image is present before creating the container
reader, err := cli.ImagePull(ctx, internal.NsenterImage, types.ImagePullOptions{
Platform: "linux/" + runtime.GOARCH,
})
if err != nil {
log.Error(err)
return m, err
}
_, err = io.Copy(os.Stdout, reader)
if err != nil {
log.Error(err)
return m, err
}

resp, err := cli.ContainerCreate(ctx, &container.Config{
Expand All @@ -52,37 +54,36 @@ func GetVolumesSize(ctx context.Context, cli *client.Client, volumeName string)
Privileged: true,
}, nil, nil, "")
if err != nil {
log.Error(err)
return m, err
}

if err := cli.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{}); err != nil {
log.Error(err)
return m, err
}

statusCh, errCh := cli.ContainerWait(ctx, resp.ID, container.WaitConditionNotRunning)
select {
case err := <-errCh:
if err != nil {
panic(err)
return m, err
}
case <-statusCh:
}

out, err := cli.ContainerLogs(ctx, resp.ID, types.ContainerLogsOptions{ShowStdout: true})
if err != nil {
log.Error(err)
return m, err
}

buf := new(bytes.Buffer)
_, err = buf.ReadFrom(out)
if err != nil {
log.Error(err)
return m, err
}

output := buf.String()

lines := strings.Split(strings.TrimSuffix(output, "\n"), "\n")
m := make(map[string]VolumeSize)
for _, line := range lines {
s := strings.Split(line, "\t") // e.g. 924 /var/lib/docker/volumes/my-volume
if len(s) != 2 {
Expand Down Expand Up @@ -118,10 +119,10 @@ func GetVolumesSize(ctx context.Context, cli *client.Client, volumeName string)

err = cli.ContainerRemove(ctx, resp.ID, types.ContainerRemoveOptions{})
if err != nil {
log.Error(err)
return m, err
}

return m
return m, nil
}

// byteCountSI converts a size in bytes to a human-readable string in SI (decimal) format.
Expand Down
Loading

0 comments on commit 37a42db

Please sign in to comment.