Skip to content

Commit

Permalink
Merge pull request #50 from picosh/am/update-sftp
Browse files Browse the repository at this point in the history
Fixed issues with sftp file listing and downloading from minio
  • Loading branch information
antoniomika authored Nov 9, 2023
2 parents 429d656 + e506aee commit 4cef657
Show file tree
Hide file tree
Showing 46 changed files with 471 additions and 385 deletions.
20 changes: 18 additions & 2 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,24 @@ inputs:
required: true
platforms:
description: The docker platforms to build for
required: false
required: true
default: |
linux/amd64
linux/arm64
registry:
description: The docker registry to use
required: false
required: true
default: ghcr.io
web:
description: Whether or not to build the web image
required: true
default: true
type: boolean
ssh:
description: Whether or not to build the ssh image
required: true
default: true
type: boolean

runs:
using: composite
Expand All @@ -31,6 +41,7 @@ runs:
with:
images: ${{ inputs.REGISTRY }}/${{ github.repository }}/${{ inputs.app }}-ssh
- name: Build and push web
if: inputs.web == 'true'
uses: docker/build-push-action@v3
with:
context: .
Expand All @@ -39,9 +50,12 @@ runs:
labels: ${{ steps.webmeta.outputs.labels }}
target: release-web
platforms: ${{ inputs.platforms }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
APP=${{ inputs.app }}
- name: Build and push ssh
if: inputs.ssh == 'true'
uses: docker/build-push-action@v3
with:
context: .
Expand All @@ -50,5 +64,7 @@ runs:
labels: ${{ steps.sshmeta.outputs.labels }}
target: release-ssh
platforms: ${{ inputs.platforms }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
APP=${{ inputs.app }}
34 changes: 34 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Setup main action

description: Runs the setup required for docker building

inputs:
registry:
description: The docker registry to use
required: true
default: ghcr.io
username:
description: The docker registry to use
required: true
password:
description: The docker registry to use
required: true

runs:
using: composite
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: all
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
with:
version: latest
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
registry: ${{ inputs.registry }}
username: ${{ inputs.username }}
password: ${{ inputs.password }}
99 changes: 51 additions & 48 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,86 +39,87 @@ jobs:
run: |
go test -v ./... -cover -race -coverprofile=coverage.out
go tool cover -func=coverage.out -o=coverage.out
build:
build-main:
runs-on: ubuntu-22.04
needs: test
strategy:
matrix:
APP: [lists, prose, pastes, imgs, pgs, feeds]
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: all
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
with:
version: latest
- name: Login to Docker Hub
uses: docker/login-action@v2
- name: Setup docker
uses: ./.github/actions/setup
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Run docker build for lists
- name: Run docker build for ${{ matrix.APP }}
uses: ./.github/actions/build
with:
app: lists
app: ${{ matrix.APP }}
platforms: ${{ env.PLATFORMS }}
registry: ${{ env.REGISTRY }}
- name: Run docker build for prose
uses: ./.github/actions/build
build-auth:
runs-on: ubuntu-22.04
needs: test
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Setup docker
uses: ./.github/actions/setup
with:
app: prose
platforms: ${{ env.PLATFORMS }}
registry: ${{ env.REGISTRY }}
- name: Run docker build for pastes
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Run docker build for auth
uses: ./.github/actions/build
with:
app: pastes
app: auth
platforms: ${{ env.PLATFORMS }}
registry: ${{ env.REGISTRY }}
- name: Run docker build for imgs
uses: ./.github/actions/build
ssh: false
build-bouncer:
runs-on: ubuntu-22.04
needs: test
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Setup docker
uses: ./.github/actions/setup
with:
app: imgs
platforms: ${{ env.PLATFORMS }}
registry: ${{ env.REGISTRY }}
- name: Run docker build for pgs
uses: ./.github/actions/build
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Collect bouncer image metadata
id: bouncermeta
uses: docker/metadata-action@v4
with:
app: pgs
platforms: ${{ env.PLATFORMS }}
registry: ${{ env.REGISTRY }}
- name: Run docker build for feeds
uses: ./.github/actions/build
images: ${{ env.REGISTRY }}/${{ github.repository }}/bouncer
- name: Build and push
uses: docker/build-push-action@v3
with:
app: feeds
context: ./bouncer
push: true
tags: ${{ steps.bouncermeta.outputs.tags }}
labels: ${{ steps.bouncermeta.outputs.labels }}
platforms: ${{ env.PLATFORMS }}
registry: ${{ env.REGISTRY }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-caddy:
runs-on: ubuntu-22.04
needs: test
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: all
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
with:
version: latest
- name: Login to Docker Hub
uses: docker/login-action@v2
- name: Setup docker
uses: ./.github/actions/setup
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Collect image metadata
id: meta
- name: Collect caddy image metadata
id: caddymeta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ github.repository }}/caddy
Expand All @@ -127,6 +128,8 @@ jobs:
with:
context: ./caddy
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
tags: ${{ steps.caddymeta.outputs.tags }}
labels: ${{ steps.caddymeta.outputs.labels }}
platforms: ${{ env.PLATFORMS }}
cache-from: type=gha
cache-to: type=gha,mode=max
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ bp-setup:
.PHONY: bp-setup

bp-caddy: bp-setup
$(DOCKER_BUILDX_BUILD) -t ghcr.io/picosh/pico/caddy:$(DOCKER_TAG) -f caddy/Dockerfile .
$(DOCKER_BUILDX_BUILD) -t ghcr.io/picosh/pico/caddy:$(DOCKER_TAG) ./caddy
.PHONY: bp-caddy

bp-auth: bp-setup
$(DOCKER_BUILDX_BUILD) -t ghcr.io/picosh/pico/auth:$(DOCKER_TAG) --build-arg APP=auth --target release-web .
.PHONY: bp-auth

bp-bouncer: bp-setup
$(DOCKER_BUILDX_BUILD) -t ghcr.io/picosh/pico/bouncer:$(DOCKER_TAG) -f bouncer/Dockerfile ./bouncer
$(DOCKER_BUILDX_BUILD) -t ghcr.io/picosh/pico/bouncer:$(DOCKER_TAG) ./bouncer
.PHONY: bp-bouncer

bp-%: bp-setup
Expand Down
2 changes: 1 addition & 1 deletion cmd/feeds/ssh/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"time"

"github.com/charmbracelet/promwish"
"github.com/charmbracelet/ssh"
"github.com/charmbracelet/wish"
bm "github.com/charmbracelet/wish/bubbletea"
lm "github.com/charmbracelet/wish/logging"
"github.com/gliderlabs/ssh"
"github.com/picosh/pico/db/postgres"
"github.com/picosh/pico/feeds"
"github.com/picosh/pico/filehandlers"
Expand Down
2 changes: 1 addition & 1 deletion cmd/imgs/ssh/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"time"

"github.com/charmbracelet/promwish"
"github.com/charmbracelet/ssh"
"github.com/charmbracelet/wish"
bm "github.com/charmbracelet/wish/bubbletea"
lm "github.com/charmbracelet/wish/logging"
"github.com/gliderlabs/ssh"
"github.com/picosh/pico/db/postgres"
uploadimgs "github.com/picosh/pico/filehandlers/imgs"
"github.com/picosh/pico/imgs"
Expand Down
2 changes: 1 addition & 1 deletion cmd/lists/ssh/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"time"

"github.com/charmbracelet/promwish"
"github.com/charmbracelet/ssh"
"github.com/charmbracelet/wish"
bm "github.com/charmbracelet/wish/bubbletea"
lm "github.com/charmbracelet/wish/logging"
"github.com/gliderlabs/ssh"
"github.com/picosh/pico/db/postgres"
"github.com/picosh/pico/filehandlers"
"github.com/picosh/pico/lists"
Expand Down
2 changes: 1 addition & 1 deletion cmd/prose/ssh/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"time"

"github.com/charmbracelet/promwish"
"github.com/charmbracelet/ssh"
"github.com/charmbracelet/wish"
bm "github.com/charmbracelet/wish/bubbletea"
lm "github.com/charmbracelet/wish/logging"
"github.com/gliderlabs/ssh"
"github.com/picosh/pico/db/postgres"
"github.com/picosh/pico/filehandlers"
"github.com/picosh/pico/prose"
Expand Down
8 changes: 5 additions & 3 deletions filehandlers/assets/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"
"time"

"github.com/gliderlabs/ssh"
"github.com/charmbracelet/ssh"
"github.com/picosh/pico/db"
"github.com/picosh/pico/shared"
"github.com/picosh/pico/shared/storage"
Expand Down Expand Up @@ -82,7 +82,7 @@ func (h *UploadAssetHandler) Read(s ssh.Session, entry *utils.FileEntry) (os.Fil
fileInfo := &utils.VirtualFile{
FName: filepath.Base(entry.Filepath),
FIsDir: false,
FSize: int64(entry.Size),
FSize: entry.Size,
FModTime: time.Unix(entry.Mtime, 0),
}

Expand All @@ -97,7 +97,9 @@ func (h *UploadAssetHandler) Read(s ssh.Session, entry *utils.FileEntry) (os.Fil
return nil, nil, err
}

return fileInfo, contents, nil
reader := utils.NewAllReaderAt(contents)

return fileInfo, reader, nil
}

func (h *UploadAssetHandler) List(s ssh.Session, fpath string) ([]os.FileInfo, error) {
Expand Down
6 changes: 4 additions & 2 deletions filehandlers/imgs/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"path/filepath"
"time"

"github.com/gliderlabs/ssh"
"github.com/charmbracelet/ssh"
exifremove "github.com/neurosnap/go-exif-remove"
"github.com/picosh/pico/db"
"github.com/picosh/pico/shared"
Expand Down Expand Up @@ -106,7 +106,9 @@ func (h *UploadImgHandler) Read(s ssh.Session, entry *utils.FileEntry) (os.FileI
return nil, nil, err
}

return fileInfo, contents, nil
reader := utils.NewAllReaderAt(contents)

return fileInfo, reader, nil
}

func (h *UploadImgHandler) List(s ssh.Session, fpath string) ([]os.FileInfo, error) {
Expand Down
2 changes: 1 addition & 1 deletion filehandlers/imgs/img.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"fmt"
"strings"

"github.com/gliderlabs/ssh"
"github.com/charmbracelet/ssh"
"github.com/picosh/pico/db"
"github.com/picosh/pico/shared"
"github.com/picosh/pico/shared/storage"
Expand Down
6 changes: 4 additions & 2 deletions filehandlers/post_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strings"
"time"

"github.com/gliderlabs/ssh"
"github.com/charmbracelet/ssh"
"github.com/picosh/pico/db"
"github.com/picosh/pico/imgs"
"github.com/picosh/pico/shared"
Expand Down Expand Up @@ -84,7 +84,9 @@ func (h *ScpUploadHandler) Read(s ssh.Session, entry *utils.FileEntry) (os.FileI
FModTime: *post.UpdatedAt,
}

return fileInfo, strings.NewReader(post.Text), nil
reader := strings.NewReader(post.Text)

return fileInfo, reader, nil
}

func (h *ScpUploadHandler) List(s ssh.Session, fpath string) ([]os.FileInfo, error) {
Expand Down
Loading

0 comments on commit 4cef657

Please sign in to comment.