From c60e61b69e2667a3a203c3d22613e797cc400983 Mon Sep 17 00:00:00 2001 From: Tobias Fenster Date: Sun, 14 Aug 2022 23:47:01 +0200 Subject: [PATCH] initial working --- Dockerfile | 15 +--- metadata.json | 4 +- tfe.png | Bin 0 -> 2327 bytes tfe.svg | 25 +++++++ ui/package-lock.json | 89 ++++++++++++++++++++++ ui/package.json | 2 + ui/src/App.tsx | 171 +++++++++++++++++++++++++++++++++++++------ vm/go.mod | 20 ----- vm/go.sum | 42 ----------- vm/main.go | 48 ------------ 10 files changed, 269 insertions(+), 147 deletions(-) create mode 100644 tfe.png create mode 100644 tfe.svg delete mode 100644 vm/go.mod delete mode 100644 vm/go.sum delete mode 100644 vm/main.go diff --git a/Dockerfile b/Dockerfile index 1117f0d..69b5d8d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,3 @@ -FROM golang:1.17-alpine AS builder -ENV CGO_ENABLED=0 -WORKDIR /backend -COPY vm/go.* . -RUN --mount=type=cache,target=/go/pkg/mod \ - --mount=type=cache,target=/root/.cache/go-build \ - go mod download -COPY vm/. . -RUN --mount=type=cache,target=/go/pkg/mod \ - --mount=type=cache,target=/root/.cache/go-build \ - go build -trimpath -ldflags="-s -w" -o bin/service - FROM --platform=$BUILDPLATFORM node:17.7-alpine3.14 AS client-builder WORKDIR /ui # cache packages in layer @@ -33,9 +21,8 @@ LABEL org.opencontainers.image.title="image-size-extension" \ com.docker.extension.additional-urls="" \ com.docker.extension.changelog="" -COPY --from=builder /backend/bin/service / COPY docker-compose.yaml . COPY metadata.json . -COPY docker.svg . +COPY tfe.svg . COPY --from=client-builder /ui/build ui CMD /service -socket /run/guest-services/extension-image-size-extension.sock diff --git a/metadata.json b/metadata.json index 7a0fed3..245f9b0 100644 --- a/metadata.json +++ b/metadata.json @@ -1,5 +1,5 @@ { - "icon": "docker.svg", + "icon": "tfe.svg", "vm": { "composefile": "docker-compose.yaml", "exposes": { @@ -8,7 +8,7 @@ }, "ui": { "dashboard-tab": { - "title": "Image-Size-Extension", + "title": "Image size", "src": "index.html", "root": "ui", "backend": { diff --git a/tfe.png b/tfe.png new file mode 100644 index 0000000000000000000000000000000000000000..4690f1762c26935affc4bb7d0e7aa31073e138c9 GIT binary patch literal 2327 zcmV+y3F!8TP)f5%}d{(d5;dBKmmE1!q zI?g^U+7&VptWZd;@UKT7k(#;U{DvD634!3CB8pCW{^oteVY zYBkP1P!5cm!hwN-`2NbizBgrkX^>T7>n6!c;X=>w^gz*6p0n7Y%X)?oh^??Vzkw%_ zT)tAWuTtTE)_oT7PYmD=aG;+3LZXQ5I{?Z+x*=>(+1;)3>)IL-F?+UqoWXJ+N~_f* zXth1NYo3%F@;vK#A{H=#;Lt@B!BAsk zDU^;2P~LuA>N}XEG7Q(4>znHUKmp)Fn@GpQ)?5Q}06vA%AO6YNdZ8e`dEN1)tOT$z z{dXekc_Ox@TQ}di!{fCi7@pR9OHaRj``tTNSK3oIZhSNQ&r4Zr#W6ASE3NlzW4()s zKvGgrx6KkaE+GthenOMiYj<<+c)HAfNbzJe57gsy$OfQ(xOHl^8+_2BJSz>lq&5`iTB8Uw&qN{wrndo{Y+KF{T$}*0XuM#ek86 zdo~M9+d#UsA6x<=a9LHN{>c~Wxi^-d^ojy7aCc%0TPAA+W-`8HI$uZz3M$RY>USS-r$Qu2Eb! zx>fAajEeJgIBu=!+@uZyAA>p&Y(1aRfk43GEt0F9bwm4tK{bd1$=0y7Dqxs+9u{fE{X4q9RqvDyqvQ3Nb0+#biqN49 zYmaARsCFU-inf9zdH7JhN;aH<5sW!BZxYG=BIc$Y3(uf5xIURm_LNO?1OS`@0I0@) zh!H3}e(${6al}bUHq#mrbYJ=W5rP+bXvA z-$XwK!6Y)NVh913j<~IK`p3g0@Rm3O*)vCH^`O~g5@EQP%#YF>P80)#lZrR|c8ws9> z1#D>RwewUexrajJ>Pma&Ua%)JMZLbj65A`DJRYBQMqm8LiputOsh@1CmzN*#_J-b| zXQLtl?cx7GrG+dITj6NNvZQcsNK{ZmfY5kH#m%ff=6LQoyrY7f-1tm_65}r5!m-=C z!K-p1n@uCA9rb!jw@pD<@8{id-{|$a23;_>c{vOYog$HN0jST+y_x%go{{2-*cFdJaR2_(IK#6!9!dfO>+1^(vEMr#BR{e^ zi2e?}+;VSs@4C3em>SH8h~QxVGlu7Qdth^nVN1jNjl5%d4+`S!bDh_^eri4&e2vLu zGD859$+Vu;d&nnqI6wMqrq|ZiF8y%!3q^ABrsvz0$;lffmUx@MEd5J(e+Gl0iXD1^ z&#^>bX{f6jEU(YThhbJ&YWwQI>z^**&L6tcg~8Y#b~05?BI1J|nxdyH#a$p2gWUhL zlAV)ErP5~f~57EXgC%{jbz?bNMi5xCSklQWv$Byvk|A za|Z`1b^7$tiJF6KL!nS8;kZSM7Ab zTa)apA;_AyRaI40%0anYF1MTm#OZ{hq9ekvw9wFx-ur5SaPt7kUGFU}E-wBYq@<*z zzyJUMXTgl$FfIlQKocB756E(ZcyEPAPfOOol+u1?4x7_ND{E_OYwyPzo=CkB;=`0S zf$gC=Os7#h{AujbYcv|o1(>|%!DGIA0W~e4F+k>H`sy2& z8X7uBMLbDdXON%A?@Xv!n85+7)yckt7w`&KKqfi`9XJ=w!mfiQuVQR6Q1AIGVGFJW* zxWX`0Zj-{^MR0Xh$=sV<%GZ3~(_%PFD=e9tS)EQVnOmQ!E)9?^^xU1DR<;eXHgF^$ z956hqaK&z<0pKGQDyscz%2cuU?%npn1}KOvrlf_>X-j%?;$`Wrz1O$!1&wZP0_jwb zf{=u + + + + + + + + + diff --git a/ui/package-lock.json b/ui/package-lock.json index 1b22e46..a6b0920 100644 --- a/ui/package-lock.json +++ b/ui/package-lock.json @@ -12,6 +12,8 @@ "@docker/extension-api-client": "^0.2.3", "@emotion/react": "^11.9.0", "@emotion/styled": "^11.8.1", + "@mui/icons-material": "^5.8.4", + "@mui/lab": "^5.0.0-alpha.94", "@mui/material": "^5.6.1", "cra-template": "1.1.3", "react": "^17.0.2", @@ -3091,6 +3093,71 @@ } } }, + "node_modules/@mui/icons-material": { + "version": "5.8.4", + "resolved": "https://registry.npmjs.org/@mui/icons-material/-/icons-material-5.8.4.tgz", + "integrity": "sha512-9Z/vyj2szvEhGWDvb+gG875bOGm8b8rlHBKOD1+nA3PcgC3fV6W1AU6pfOorPeBfH2X4mb9Boe97vHvaSndQvA==", + "dependencies": { + "@babel/runtime": "^7.17.2" + }, + "engines": { + "node": ">=12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/mui" + }, + "peerDependencies": { + "@mui/material": "^5.0.0", + "@types/react": "^17.0.0 || ^18.0.0", + "react": "^17.0.0 || ^18.0.0" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } + } + }, + "node_modules/@mui/lab": { + "version": "5.0.0-alpha.94", + "resolved": "https://registry.npmjs.org/@mui/lab/-/lab-5.0.0-alpha.94.tgz", + "integrity": "sha512-1GjH70Th5SBMJbUR1LQTCrdKMcdUSEduZ7foy80kMlzUUQXwV50iwWzeGa1WMP4mgCQ94i+3n704IYHIxC6KNg==", + "dependencies": { + "@babel/runtime": "^7.17.2", + "@mui/base": "5.0.0-alpha.92", + "@mui/system": "^5.10.0", + "@mui/utils": "^5.9.3", + "clsx": "^1.2.1", + "prop-types": "^15.8.1", + "react-is": "^18.2.0" + }, + "engines": { + "node": ">=12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/mui" + }, + "peerDependencies": { + "@emotion/react": "^11.5.0", + "@emotion/styled": "^11.3.0", + "@mui/material": "^5.0.0", + "@types/react": "^17.0.0 || ^18.0.0", + "react": "^17.0.0 || ^18.0.0", + "react-dom": "^17.0.0 || ^18.0.0" + }, + "peerDependenciesMeta": { + "@emotion/react": { + "optional": true + }, + "@emotion/styled": { + "optional": true + }, + "@types/react": { + "optional": true + } + } + }, "node_modules/@mui/material": { "version": "5.10.0", "resolved": "https://registry.npmjs.org/@mui/material/-/material-5.10.0.tgz", @@ -18770,6 +18837,28 @@ "react-is": "^18.2.0" } }, + "@mui/icons-material": { + "version": "5.8.4", + "resolved": "https://registry.npmjs.org/@mui/icons-material/-/icons-material-5.8.4.tgz", + "integrity": "sha512-9Z/vyj2szvEhGWDvb+gG875bOGm8b8rlHBKOD1+nA3PcgC3fV6W1AU6pfOorPeBfH2X4mb9Boe97vHvaSndQvA==", + "requires": { + "@babel/runtime": "^7.17.2" + } + }, + "@mui/lab": { + "version": "5.0.0-alpha.94", + "resolved": "https://registry.npmjs.org/@mui/lab/-/lab-5.0.0-alpha.94.tgz", + "integrity": "sha512-1GjH70Th5SBMJbUR1LQTCrdKMcdUSEduZ7foy80kMlzUUQXwV50iwWzeGa1WMP4mgCQ94i+3n704IYHIxC6KNg==", + "requires": { + "@babel/runtime": "^7.17.2", + "@mui/base": "5.0.0-alpha.92", + "@mui/system": "^5.10.0", + "@mui/utils": "^5.9.3", + "clsx": "^1.2.1", + "prop-types": "^15.8.1", + "react-is": "^18.2.0" + } + }, "@mui/material": { "version": "5.10.0", "resolved": "https://registry.npmjs.org/@mui/material/-/material-5.10.0.tgz", diff --git a/ui/package.json b/ui/package.json index 626a994..18725b9 100644 --- a/ui/package.json +++ b/ui/package.json @@ -7,6 +7,8 @@ "@docker/extension-api-client": "^0.2.3", "@emotion/react": "^11.9.0", "@emotion/styled": "^11.8.1", + "@mui/icons-material": "^5.8.4", + "@mui/lab": "^5.0.0-alpha.94", "@mui/material": "^5.6.1", "cra-template": "1.1.3", "react": "^17.0.2", diff --git a/ui/src/App.tsx b/ui/src/App.tsx index 28ca073..1b266bc 100644 --- a/ui/src/App.tsx +++ b/ui/src/App.tsx @@ -2,6 +2,10 @@ import React from 'react'; import Button from '@mui/material/Button'; import { createDockerDesktopClient } from '@docker/extension-api-client'; import { Stack, TextField, Typography } from '@mui/material'; +import TreeView from '@mui/lab/TreeView'; +import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; +import ChevronRightIcon from '@mui/icons-material/ChevronRight'; +import TreeItem from '@mui/lab/TreeItem'; // Note: This line relies on Docker Desktop's presence as a host application. // If you're running this React app in a browser, it won't work properly. @@ -11,42 +15,167 @@ function useDockerDesktopClient() { return client; } +function formatBytes(bytes, decimals = 2) { + // from https://stackoverflow.com/questions/15900485/correct-way-to-convert-size-in-bytes-to-kb-mb-gb-in-javascript + if (bytes === 0) return '0 Bytes'; + + const k = 1024; + const dm = decimals < 0 ? 0 : decimals; + const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; + + const i = Math.floor(Math.log(bytes) / Math.log(k)); + + return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]; +} + +interface Manifest { + Ref: string; + Descriptor: Descriptor; + SchemaV2Manifest: SchemaManifest; +} + +interface Descriptor { + mediaType: string; + digest: string; + size: number; + platform: Platform; +} + +interface Platform { + architecture: string; + os: string; + osversion: string; +} + +interface Layer { + mediaType: string; + size: number; + digest: string; + urls: string[]; +} + +interface Config { + mediaType: string; + size: number; + digest: string; +} + +interface SchemaManifest { + schemaVersion: number; + mediaType: string; + config: Config; + layers: Layer[]; +} + export function App() { - const [response, setResponse] = React.useState(); + const [buttonText, setButtonText] = React.useState(); + const [imagename, setImagename] = React.useState(); + const [manifests, setManifests] = React.useState(); const ddClient = useDockerDesktopClient(); const fetchAndDisplayResponse = async () => { - const result = await ddClient.extension.vm?.service?.get('/hello'); - setResponse(JSON.stringify(result)); + setButtonText("Loading ...") + try { + const manifestInfo = await ddClient.docker.cli.exec("manifest", [ + "inspect", + imagename, + "-v" + ]); + + const parsedManifestInfo: Manifest | Manifest[] = manifestInfo.parseJsonObject(); + var localManifests: Manifest[]; + if (!Array.isArray(parsedManifestInfo)) { + localManifests = [parsedManifestInfo]; + } else { + localManifests = parsedManifestInfo; + } + setManifests(localManifests); + } catch (e) { + setManifests(undefined); + console.log(e.stderr); + ddClient.desktopUI.toast.error(e.stderr); + } + setButtonText(undefined); + }; + + function RenderResultTree() { + if (manifests !== undefined) { + return ( + } + defaultExpandIcon={} + sx={{ flexGrow: 1, overflowY: 'auto' }} + disableSelection={true} + > + { + manifests.map((manifest: Manifest, index: number) => { + var localRef = manifest.Ref; + if (localRef.indexOf("@") > 0) + localRef = localRef.substring(0, localRef.indexOf("@")); + + localRef += ` (${manifest.Descriptor.platform.os} - ${manifest.Descriptor.platform.architecture}`; + if (manifest.Descriptor.platform["os.version"] !== undefined) + localRef += ` - ${manifest.Descriptor.platform["os.version"]}`; + localRef += ")"; + + var configSize = manifest.SchemaV2Manifest.config.size; + var totalLayerSize = configSize; + manifest.SchemaV2Manifest.layers.forEach((layer: Layer) => { + totalLayerSize += layer.size; + }); + var totalSize = configSize + totalLayerSize; + + return ( + + + + + { + manifest.SchemaV2Manifest.layers.map((layer: Layer, indexLayer: number) => { + return ( + + ); + }) + } + + + ); + }) + } + + ); + } + } + + const handleImagenameChange = event => { + setImagename(event.target.value); }; return ( <> - Docker extension demo + Docker image size - This is a basic page rendered with MUI, using Docker's theme. Read the - MUI documentation to learn more. Using MUI in a conventional way and - avoiding custom styling will help make sure your extension continues to - look great as Docker's theme evolves. + This extension allows you to query any publicly available Docker image for its compressed size. - Pressing the below button will trigger a request to the backend. Its - response will appear in the textarea. + Entering the name (and tag) of a Docker image in the entry field below and then pressing the button will retrieve and calculate the size. - - - + + + + + + {RenderResultTree()} ); diff --git a/vm/go.mod b/vm/go.mod deleted file mode 100644 index f9cd12b..0000000 --- a/vm/go.mod +++ /dev/null @@ -1,20 +0,0 @@ -module image-size-extension - -go 1.17 - -require ( - github.com/labstack/echo v3.3.10+incompatible - github.com/sirupsen/logrus v1.9.0 -) - -require ( - 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 - github.com/valyala/bytebufferpool v1.0.0 // indirect - github.com/valyala/fasttemplate v1.2.1 // indirect - golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa // indirect - golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect - golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect - golang.org/x/text v0.3.6 // indirect -) diff --git a/vm/go.sum b/vm/go.sum deleted file mode 100644 index fe34cf2..0000000 --- a/vm/go.sum +++ /dev/null @@ -1,42 +0,0 @@ -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/labstack/echo v3.3.10+incompatible h1:pGRcYk231ExFAyoAjAfD85kQzRJCRI8bbnE7CX5OEgg= -github.com/labstack/echo v3.3.10+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8cVwCLbBmJyDaka6Cmk1s= -github.com/labstack/gommon v0.3.1 h1:OomWaJXm7xR6L1HmEtGyQf26TEn7V6X88mktX9kee9o= -github.com/labstack/gommon v0.3.1/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM= -github.com/mattn/go-colorable v0.1.11 h1:nQ+aFkoE2TMGc0b68U2OKSexC+eq46+XwZzWXHRmPYs= -github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= -github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= -github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= -github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= -github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= -github.com/valyala/fasttemplate v1.2.1 h1:TVEnxayobAdVkhQfrfes2IzOB6o+z4roRkPF52WA1u4= -github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= -golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa h1:zuSxTR4o9y82ebqCUJYNGJbGPo6sKVl54f/TVDObg1c= -golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE= -golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211103235746-7861aae1554b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ= -golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= -golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/vm/main.go b/vm/main.go deleted file mode 100644 index c8a4fc4..0000000 --- a/vm/main.go +++ /dev/null @@ -1,48 +0,0 @@ -package main - -import ( - "flag" - "log" - "net" - "net/http" - "os" - - "github.com/labstack/echo" - "github.com/sirupsen/logrus" -) - -func main() { - var socketPath string - flag.StringVar(&socketPath, "socket", "/run/guest/volumes-service.sock", "Unix domain socket to listen on") - flag.Parse() - - os.RemoveAll(socketPath) - - logrus.New().Infof("Starting listening on %s\n", socketPath) - router := echo.New() - router.HideBanner = true - - startURL := "" - - ln, err := listen(socketPath) - if err != nil { - log.Fatal(err) - } - router.Listener = ln - - router.GET("/hello", hello) - - log.Fatal(router.Start(startURL)) -} - -func listen(path string) (net.Listener, error) { - return net.Listen("unix", path) -} - -func hello(ctx echo.Context) error { - return ctx.JSON(http.StatusOK, HTTPMessageBody{Message: "hello"}) -} - -type HTTPMessageBody struct { - Message string -}