fix: build GTS docker image from base Alpine image
Changes: - Update the Dockerfile template to build the GTS image from alpine:3.17. - Add logic to download and verify GTS packages. - Allow the Download target to be more forgiving for a service that does not need to download any files. - The Download target is now a dependency to the Render target for all services that aren't named 'compose'. - Update the path to the web files in the GTS config file. - Update the entrypoint to use the correct path of the GTS executable file. Chores: - Remove unused DockerImageDigest setting from GTS config.
This commit is contained in:
parent
5f00909726
commit
042f3e2364
8 changed files with 144 additions and 24 deletions
|
@ -59,7 +59,6 @@ type forgejoConfig struct {
|
|||
|
||||
type gotosocialConfig struct {
|
||||
Version string `json:"version"`
|
||||
DockerImageDigest string `json:"dockerImageDigest"`
|
||||
Name string `json:"name"`
|
||||
LogLevel string `json:"logLevel"`
|
||||
LinuxUID int32 `json:"linuxUID"`
|
||||
|
|
|
@ -111,8 +111,7 @@ func downloadForgejo(version string) error {
|
|||
return fmt.Errorf("GPG verification failed; %w", err)
|
||||
}
|
||||
|
||||
err = os.Chdir(downloadFolder)
|
||||
if err != nil {
|
||||
if err := os.Chdir(downloadFolder); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
109
magefiles/download_gotosocial.go
Normal file
109
magefiles/download_gotosocial.go
Normal file
|
@ -0,0 +1,109 @@
|
|||
//go:build mage
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/magefile/mage/sh"
|
||||
)
|
||||
|
||||
func downloadGoToSocial(version string) error {
|
||||
downloadFolder := filepath.Join(rootBuildDir, "gotosocial")
|
||||
|
||||
if err := os.MkdirAll(downloadFolder, 0o750); err != nil {
|
||||
return fmt.Errorf("unable to make %s; %w", downloadFolder, err)
|
||||
}
|
||||
|
||||
binaryTarUrl := fmt.Sprintf(
|
||||
"https://github.com/superseriousbusiness/gotosocial/releases/download/v%s/gotosocial_%s_linux_amd64.tar.gz",
|
||||
version,
|
||||
version,
|
||||
)
|
||||
binaryTarFilepath := filepath.Join(downloadFolder, fmt.Sprintf("gotosocial_%s_linux_amd64.tar.gz", version))
|
||||
|
||||
webAssetsTarUrl := fmt.Sprintf(
|
||||
"https://github.com/superseriousbusiness/gotosocial/releases/download/v%s/gotosocial_%s_web-assets.tar.gz",
|
||||
version,
|
||||
version,
|
||||
)
|
||||
webAssetsFilepath := filepath.Join(downloadFolder, fmt.Sprintf("gotosocial_%s_web-assets.tar.gz", version))
|
||||
|
||||
checksumUrl := fmt.Sprintf(
|
||||
"https://github.com/superseriousbusiness/gotosocial/releases/download/v%s/checksums.txt",
|
||||
version,
|
||||
)
|
||||
checksumFilePath := filepath.Join(downloadFolder, fmt.Sprintf("gotosocial_%s_checksums.txt", version))
|
||||
|
||||
_, err := os.Stat(binaryTarFilepath)
|
||||
if err == nil {
|
||||
fmt.Printf("GoToSocial %s is already downloaded.\n", version)
|
||||
return nil
|
||||
}
|
||||
|
||||
downloads := []struct {
|
||||
url string
|
||||
path string
|
||||
}{
|
||||
{
|
||||
url: binaryTarUrl,
|
||||
path: binaryTarFilepath,
|
||||
},
|
||||
{
|
||||
url: webAssetsTarUrl,
|
||||
path: webAssetsFilepath,
|
||||
},
|
||||
{
|
||||
url: checksumUrl,
|
||||
path: checksumFilePath,
|
||||
},
|
||||
}
|
||||
|
||||
for _, v := range downloads {
|
||||
if err := func() error {
|
||||
download, err := os.Create(v.path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to create %s; %w", v.path, err)
|
||||
}
|
||||
defer download.Close()
|
||||
|
||||
client := http.Client{
|
||||
CheckRedirect: func(r *http.Request, _ []*http.Request) error {
|
||||
r.URL.Opaque = r.URL.Path
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
resp, err := client.Get(v.url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
size, err := io.Copy(download, resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("Downloaded %s with size %d.\n", v.path, size)
|
||||
|
||||
return nil
|
||||
}(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := os.Chdir(downloadFolder); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := sh.Run("sha256sum", "--check", "--ignore-missing", fmt.Sprintf("gotosocial_%s_checksums.txt", version)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
|
@ -38,19 +38,24 @@ func Clean() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Download downaloads the binaries for a given service.
|
||||
// Download downloads the binaries for a given service.
|
||||
func Download(name string) error {
|
||||
cfg, err := newConfig(configFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to load the configuration; %v", err)
|
||||
}
|
||||
|
||||
if name == "forgejo" {
|
||||
switch name {
|
||||
case "forgejo":
|
||||
if err := downloadForgejo(cfg.Forgejo.Version); err != nil {
|
||||
return fmt.Errorf("an error occurred whilst getting the forgejo binary; %w", err)
|
||||
}
|
||||
} else {
|
||||
return fmt.Errorf("unsupported service: %s", name)
|
||||
case "gotosocial":
|
||||
if err := downloadGoToSocial(cfg.GoToSocial.Version); err != nil {
|
||||
return fmt.Errorf("an error occurred whilst getting the packages for GoToSocial; %w", err)
|
||||
}
|
||||
default:
|
||||
fmt.Printf("'%s' has no files to download.\n", name)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -20,12 +20,6 @@ func Render(name string) error {
|
|||
return fmt.Errorf("unable to load the configuration; %v", err)
|
||||
}
|
||||
|
||||
if name == "forgejo" || name == "all" {
|
||||
mg.Deps(
|
||||
mg.F(Download, "forgejo"),
|
||||
)
|
||||
}
|
||||
|
||||
if name == "all" {
|
||||
objects, err := os.ReadDir(rootTemplatesDir)
|
||||
if err != nil {
|
||||
|
@ -39,6 +33,12 @@ func Render(name string) error {
|
|||
|
||||
dirName := o.Name()
|
||||
|
||||
if dirName != "compose" {
|
||||
mg.Deps(
|
||||
mg.F(Download, dirName),
|
||||
)
|
||||
}
|
||||
|
||||
log.Printf("Rendering templates for %s.\n", dirName)
|
||||
if err := render(cfg, o.Name()); err != nil {
|
||||
return fmt.Errorf("unable to render templates for %s; %w", dirName, err)
|
||||
|
@ -47,6 +47,7 @@ func Render(name string) error {
|
|||
} else {
|
||||
if name != "compose" {
|
||||
mg.Deps(
|
||||
mg.F(Download, name),
|
||||
mg.F(Render, "compose"),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -1,19 +1,26 @@
|
|||
FROM superseriousbusiness/gotosocial:{{ .GoToSocial.Version }}@{{ .GoToSocial.DockerImageDigest }}
|
||||
# syntax=docker/dockerfile:1
|
||||
FROM alpine:3.17
|
||||
|
||||
USER 0
|
||||
WORKDIR /tmp
|
||||
|
||||
RUN apk update && apk upgrade && apk add bash \
|
||||
RUN --mount=type=bind,source=.,target=/packages \
|
||||
apk update --no-cache && apk add bash --no-cache \
|
||||
&& addgroup -S -g {{ .FlowGID }} flow \
|
||||
&& adduser -S -H -D -s /bin/bash -u {{ .GoToSocial.LinuxUID }} -G flow gts \
|
||||
&& chown -R {{ .GoToSocial.LinuxUID }}:{{ .GoToSocial.LinuxUID }} /gotosocial \
|
||||
&& mkdir -p /flow/gts/tmp /flow/gts/config && chown -R {{ .GoToSocial.LinuxUID }}:{{ .GoToSocial.LinuxUID }} /flow/gts
|
||||
&& mkdir -p /flow/gts/config \
|
||||
&& tar xzvf /packages/gotosocial_{{ .GoToSocial.Version }}_linux_amd64.tar.gz \
|
||||
&& tar xzvf /packages/gotosocial_{{ .GoToSocial.Version }}_web-assets.tar.gz \
|
||||
&& mv /tmp/gotosocial /usr/local/bin/gotosocial \
|
||||
&& mv /tmp/web /flow/gts \
|
||||
&& chown -R {{ .GoToSocial.LinuxUID }}:{{ .FlowGID }} /flow/gts \
|
||||
&& rm -rf /tmp/*
|
||||
|
||||
COPY --chown={{ .GoToSocial.LinuxUID }}:{{ .GoToSocial.LinuxUID }} entrypoint.sh /usr/local/bin/entrypoint.sh
|
||||
COPY --chown={{ .GoToSocial.LinuxUID }}:{{ .GoToSocial.LinuxUID }} entrypoint.sh /usr/local/bin/entrypoint
|
||||
COPY --chown={{ .GoToSocial.LinuxUID }}:{{ .GoToSocial.LinuxUID }} config.yaml /flow/gts/config/config.yaml
|
||||
COPY --chown={{ .GoToSocial.LinuxUID }}:{{ .FlowGID }} traefik_gotosocial.yaml /flow/gts/tmp/traefik_gotosocial.yaml
|
||||
|
||||
RUN chmod a+x /usr/local/bin/entrypoint.sh
|
||||
RUN chmod a+x /usr/local/bin/entrypoint
|
||||
|
||||
USER {{ .GoToSocial.LinuxUID }}:{{ .FlowGID }}
|
||||
|
||||
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
|
||||
ENTRYPOINT ["entrypoint"]
|
||||
|
|
|
@ -290,12 +290,12 @@ cache:
|
|||
# String. Directory from which gotosocial will attempt to load html templates (.tmpl files).
|
||||
# Examples: ["/some/absolute/path/", "./relative/path/", "../../some/weird/path/"]
|
||||
# Default: "./web/template/"
|
||||
web-template-base-dir: "./web/template/"
|
||||
web-template-base-dir: "/flow/gts/web/template/"
|
||||
|
||||
# String. Directory from which gotosocial will attempt to serve static web assets (images, scripts).
|
||||
# Examples: ["/some/absolute/path/", "./relative/path/", "../../some/weird/path/"]
|
||||
# Default: "./web/assets/"
|
||||
web-asset-base-dir: "./web/assets/"
|
||||
web-asset-base-dir: "/flow/gts/web/assets/"
|
||||
|
||||
###########################
|
||||
##### INSTANCE CONFIG #####
|
||||
|
|
|
@ -11,4 +11,4 @@ fi
|
|||
|
||||
mkdir -p {{ .GoToSocial.DataContainerDirectory }}/database
|
||||
|
||||
exec /gotosocial/gotosocial --config-path /flow/gts/config/config.yaml server start
|
||||
exec gotosocial --config-path /flow/gts/config/config.yaml server start
|
||||
|
|
Loading…
Reference in a new issue