Skip to content

Commit

Permalink
Add support for placing ipfs variables
Browse files Browse the repository at this point in the history
  • Loading branch information
waybackarchiver committed Jul 30, 2024
1 parent 96d3d81 commit 3a5b1d0
Show file tree
Hide file tree
Showing 14 changed files with 91 additions and 15 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ jobs:
artifact-path: ./build/binary/wayback*
egress-policy: audit
secrets:
wayback-ipfs-target: ${{ secrets.WAYBACK_IPFS_TARGET }}
wayback-ipfs-apikey: ${{ secrets.WAYBACK_IPFS_APIKEY }}
wayback-ipfs-secret: ${{ secrets.WAYBACK_IPFS_SECRET }}

debpkg:
name: Build deb
Expand All @@ -125,7 +127,9 @@ jobs:
artifact-path: build/package/wayback*.deb
egress-policy: audit
secrets:
wayback-ipfs-target: ${{ secrets.WAYBACK_IPFS_TARGET }}
wayback-ipfs-apikey: ${{ secrets.WAYBACK_IPFS_APIKEY }}
wayback-ipfs-secret: ${{ secrets.WAYBACK_IPFS_SECRET }}

rpmpkg:
name: Build RPM
Expand All @@ -136,7 +140,9 @@ jobs:
artifact-path: build/package/wayback*.rpm
egress-policy: audit
secrets:
wayback-ipfs-target: ${{ secrets.WAYBACK_IPFS_TARGET }}
wayback-ipfs-apikey: ${{ secrets.WAYBACK_IPFS_APIKEY }}
wayback-ipfs-secret: ${{ secrets.WAYBACK_IPFS_SECRET }}
wayback-signing-key: ${{ secrets.GEMFURY_SIGNING_KEY }}
wayback-signing-passpharse: ${{ secrets.GEMFURY_SIGNING_PASSPHARSE }}

Expand All @@ -152,7 +158,9 @@ jobs:
build/aur/wayback*.pkg.tar.zst
egress-policy: audit
secrets:
wayback-ipfs-target: ${{ secrets.WAYBACK_IPFS_TARGET }}
wayback-ipfs-apikey: ${{ secrets.WAYBACK_IPFS_APIKEY }}
wayback-ipfs-secret: ${{ secrets.WAYBACK_IPFS_SECRET }}

snapcraft:
name: Build Snap
Expand All @@ -163,7 +171,9 @@ jobs:
publish: ${{ github.repository == 'wabarc/wayback' && github.event_name == 'push' }}
egress-policy: audit
secrets:
wayback-ipfs-target: ${{ secrets.WAYBACK_IPFS_TARGET }}
wayback-ipfs-apikey: ${{ secrets.WAYBACK_IPFS_APIKEY }}
wayback-ipfs-secret: ${{ secrets.WAYBACK_IPFS_SECRET }}
snapcraft-token: ${{ secrets.SNAPCRAFT_TOKEN }}

flatpak:
Expand All @@ -176,4 +186,6 @@ jobs:
artifact-path: org.wabarc.wayback-*.x86_64.flatpak
egress-policy: audit
secrets:
wayback-ipfs-target: ${{ secrets.WAYBACK_IPFS_TARGET }}
wayback-ipfs-apikey: ${{ secrets.WAYBACK_IPFS_APIKEY }}
wayback-ipfs-secret: ${{ secrets.WAYBACK_IPFS_SECRET }}
8 changes: 8 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ jobs:
- name: Build artifacts
uses: docker/bake-action@6c87dcca988e4e074e3ab1f976a70f63ec9673fb # v2.3.0
env:
WAYBACK_IPFS_TARGET: ${{ secrets.WAYBACK_IPFS_TARGET }}
WAYBACK_IPFS_APIKEY: ${{ secrets.WAYBACK_IPFS_APIKEY }}
WAYBACK_IPFS_SECRET: ${{ secrets.WAYBACK_IPFS_SECRET }}
with:
files: ./docker-bake.hcl
targets: artifact-all
Expand All @@ -145,7 +147,9 @@ jobs:
- name: Build and push Docker image
uses: docker/bake-action@6c87dcca988e4e074e3ab1f976a70f63ec9673fb # v2.3.0
env:
WAYBACK_IPFS_TARGET: ${{ secrets.WAYBACK_IPFS_TARGET }}
WAYBACK_IPFS_APIKEY: ${{ secrets.WAYBACK_IPFS_APIKEY }}
WAYBACK_IPFS_SECRET: ${{ secrets.WAYBACK_IPFS_SECRET }}
with:
files: |
./docker-bake.hcl
Expand Down Expand Up @@ -271,7 +275,9 @@ jobs:
- name: Build artifacts
uses: docker/bake-action@6c87dcca988e4e074e3ab1f976a70f63ec9673fb # v2.3.0
env:
WAYBACK_IPFS_TARGET: ${{ secrets.WAYBACK_IPFS_TARGET }}
WAYBACK_IPFS_APIKEY: ${{ secrets.WAYBACK_IPFS_APIKEY }}
WAYBACK_IPFS_SECRET: ${{ secrets.WAYBACK_IPFS_SECRET }}
with:
files: ./docker-bake.hcl
targets: artifact-all
Expand All @@ -282,7 +288,9 @@ jobs:
- name: Build and push Docker image
uses: docker/bake-action@6c87dcca988e4e074e3ab1f976a70f63ec9673fb # v2.3.0
env:
WAYBACK_IPFS_TARGET: ${{ secrets.WAYBACK_IPFS_TARGET }}
WAYBACK_IPFS_APIKEY: ${{ secrets.WAYBACK_IPFS_APIKEY }}
WAYBACK_IPFS_SECRET: ${{ secrets.WAYBACK_IPFS_SECRET }}
with:
files: |
./docker-bake.hcl
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ jobs:
artifact-path: build/package/wayback*
egress-policy: audit
secrets:
wayback-ipfs-target: ${{ secrets.WAYBACK_IPFS_TARGET }}
wayback-ipfs-apikey: ${{ secrets.WAYBACK_IPFS_APIKEY }}
wayback-ipfs-secret: ${{ secrets.WAYBACK_IPFS_SECRET }}

debpkg:
name: Build DEB
Expand All @@ -110,7 +112,9 @@ jobs:
artifact-path: build/package/wayback*.deb
egress-policy: audit
secrets:
wayback-ipfs-target: ${{ secrets.WAYBACK_IPFS_TARGET }}
wayback-ipfs-apikey: ${{ secrets.WAYBACK_IPFS_APIKEY }}
wayback-ipfs-secret: ${{ secrets.WAYBACK_IPFS_SECRET }}

rpmpkg:
name: Build RPM
Expand All @@ -121,7 +125,9 @@ jobs:
artifact-path: build/package/wayback*.rpm
egress-policy: audit
secrets:
wayback-ipfs-target: ${{ secrets.WAYBACK_IPFS_TARGET }}
wayback-ipfs-apikey: ${{ secrets.WAYBACK_IPFS_APIKEY }}
wayback-ipfs-secret: ${{ secrets.WAYBACK_IPFS_SECRET }}
wayback-signing-key: ${{ secrets.GEMFURY_SIGNING_KEY }}
wayback-signing-passpharse: ${{ secrets.GEMFURY_SIGNING_PASSPHARSE }}

Expand All @@ -137,7 +143,9 @@ jobs:
build/aur/wayback*.pkg.tar.zst
egress-policy: audit
secrets:
wayback-ipfs-target: ${{ secrets.WAYBACK_IPFS_TARGET }}
wayback-ipfs-apikey: ${{ secrets.WAYBACK_IPFS_APIKEY }}
wayback-ipfs-secret: ${{ secrets.WAYBACK_IPFS_SECRET }}

snapcraft:
name: Build Snap
Expand All @@ -149,7 +157,9 @@ jobs:
publish: true
egress-policy: audit
secrets:
wayback-ipfs-target: ${{ secrets.WAYBACK_IPFS_TARGET }}
wayback-ipfs-apikey: ${{ secrets.WAYBACK_IPFS_APIKEY }}
wayback-ipfs-secret: ${{ secrets.WAYBACK_IPFS_SECRET }}
snapcraft-token: ${{ secrets.SNAPCRAFT_TOKEN }}

flatpak:
Expand All @@ -161,7 +171,9 @@ jobs:
artifact-path: org.wabarc.wayback-*.x86_64.flatpak
egress-policy: audit
secrets:
wayback-ipfs-target: ${{ secrets.WAYBACK_IPFS_TARGET }}
wayback-ipfs-apikey: ${{ secrets.WAYBACK_IPFS_APIKEY }}
wayback-ipfs-secret: ${{ secrets.WAYBACK_IPFS_SECRET }}

release:
name: Create and upload release
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/snapcraft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ jobs:
publish: true
release: true
secrets:
wayback-ipfs-target: ${{ secrets.WAYBACK_IPFS_TARGET }}
wayback-ipfs-apikey: ${{ secrets.WAYBACK_IPFS_APIKEY }}
wayback-ipfs-secret: ${{ secrets.WAYBACK_IPFS_SECRET }}
snapcraft-token: ${{ secrets.SNAPCRAFT_TOKEN }}
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ COPY --from=tonistiigi/xx:golang / /
RUN apk add --no-cache -U build-base ca-certificates linux-headers musl-dev git tar

ARG TARGETPLATFORM
ARG WAYBACK_IPFS_TARGET
ARG WAYBACK_IPFS_APIKEY
ARG WAYBACK_IPFS_SECRET

WORKDIR /src

ENV WAYBACK_IPFS_TARGET ${WAYBACK_IPFS_TARGET}
ENV WAYBACK_IPFS_APIKEY ${WAYBACK_IPFS_APIKEY}
ENV WAYBACK_IPFS_SECRET ${WAYBACK_IPFS_SECRET}

COPY . .
RUN --mount=type=bind,target=/src,rw \
Expand Down
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ PACKDIR ?= ./build/package
LDFLAGS := $(shell echo "-X '${REPO}/version.Version=`git describe --tags --abbrev=0`'")
LDFLAGS := $(shell echo "${LDFLAGS} -X '${REPO}/version.Commit=`git rev-parse --short HEAD`'")
LDFLAGS := $(shell echo "${LDFLAGS} -X '${REPO}/version.BuildDate=`date +%FT%T%z`'")
LDFLAGS := $(shell echo "${LDFLAGS} -X '${REPO}/config.IPFSToken=$(shell echo ${WAYBACK_IPFS_APIKEY})'")
LDFLAGS := $(shell echo "${LDFLAGS} -X '${REPO}/config.IPFSTarget=$(shell echo ${WAYBACK_IPFS_TARGET})'")
LDFLAGS := $(shell echo "${LDFLAGS} -X '${REPO}/config.IPFSApikey=$(shell echo ${WAYBACK_IPFS_APIKEY})'")
LDFLAGS := $(shell echo "${LDFLAGS} -X '${REPO}/config.IPFSSecret=$(shell echo ${WAYBACK_IPFS_SECRET})'")
GOBUILD ?= go build -trimpath --ldflags "-s -w ${LDFLAGS} -buildid=" -v
VERSION ?= $(shell git describe --tags `git rev-list --tags --max-count=1` | sed -e 's/v//g')
GOFILES ?= $(wildcard ./cmd/wayback/*.go)
Expand Down Expand Up @@ -152,14 +154,18 @@ profile: ## Test and profile
docker-image: ## Build Docker image
@echo "-> Building docker image..."
@$(DOCKER) build \
--build-arg WAYBACK_IPFS_TARGET=$(shell echo ${WAYBACK_IPFS_TARGET}) \
--build-arg WAYBACK_IPFS_APIKEY=$(shell echo ${WAYBACK_IPFS_APIKEY}) \
--build-arg WAYBACK_IPFS_SECRET=$(shell echo ${WAYBACK_IPFS_SECRET}) \
-t $(DOCKER_IMAGE):$(VERSION) \
-f ./build/docker/Dockerfile.dev .

rpm: ## Build RPM package
@echo "-> Building rpm package..."
@$(DOCKER) build \
--build-arg WAYBACK_IPFS_TARGET=$(shell echo ${WAYBACK_IPFS_TARGET}) \
--build-arg WAYBACK_IPFS_APIKEY=$(shell echo ${WAYBACK_IPFS_APIKEY}) \
--build-arg WAYBACK_IPFS_SECRET=$(shell echo ${WAYBACK_IPFS_SECRET}) \
-t wayback-rpm-builder \
-f build/redhat/Dockerfile .
@$(DOCKER) run --rm \
Expand All @@ -174,7 +180,9 @@ debian: ## Build Debian packages
@$(DOCKER) buildx build --load \
--platform linux/$(DOCKER_PLATFORM) \
--build-arg PKG_VERSION=$(VERSION) \
--build-arg WAYBACK_IPFS_TARGET=$(shell echo ${WAYBACK_IPFS_TARGET}) \
--build-arg WAYBACK_IPFS_APIKEY=$(shell echo ${WAYBACK_IPFS_APIKEY}) \
--build-arg WAYBACK_IPFS_SECRET=$(shell echo ${WAYBACK_IPFS_SECRET}) \
-t wayback-deb-builder \
-f build/debian/Dockerfile \
.
Expand Down
2 changes: 1 addition & 1 deletion build/aur
2 changes: 2 additions & 0 deletions build/debian/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ RUN apt-get update -q && \

COPY . /src

ENV WAYBACK_IPFS_TARGET ${WAYBACK_IPFS_TARGET}
ENV WAYBACK_IPFS_APIKEY ${WAYBACK_IPFS_APIKEY}
ENV WAYBACK_IPFS_SECRET ${WAYBACK_IPFS_SECRET}

CMD ["/src/build/debian/builder"]
6 changes: 5 additions & 1 deletion build/docker/Dockerfile.all
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ COPY --from=tonistiigi/xx:golang / /
RUN apk add --no-cache -U build-base ca-certificates linux-headers musl-dev git tar

ARG TARGETPLATFORM
ARG WAYBACK_IPFS_TARGET
ARG WAYBACK_IPFS_APIKEY
ARG WAYBACK_IPFS_SECRET

WORKDIR /src

ENV WAYBACK_IPFS_APIKEY $WAYBACK_IPFS_APIKEY
ENV WAYBACK_IPFS_TARGET ${WAYBACK_IPFS_TARGET}
ENV WAYBACK_IPFS_APIKEY ${WAYBACK_IPFS_APIKEY}
ENV WAYBACK_IPFS_SECRET ${WAYBACK_IPFS_SECRET}

COPY . .
RUN --mount=type=bind,target=/src,rw \
Expand Down
6 changes: 5 additions & 1 deletion build/docker/Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS builder
RUN apk add --no-cache -U build-base ca-certificates linux-headers musl-dev git tar

ARG TARGETPLATFORM
ARG WAYBACK_IPFS_TARGET
ARG WAYBACK_IPFS_APIKEY
ARG WAYBACK_IPFS_SECRET

WORKDIR /src

ENV WAYBACK_IPFS_APIKEY $WAYBACK_IPFS_APIKEY
ENV WAYBACK_IPFS_TARGET ${WAYBACK_IPFS_TARGET}
ENV WAYBACK_IPFS_APIKEY ${WAYBACK_IPFS_APIKEY}
ENV WAYBACK_IPFS_SECRET ${WAYBACK_IPFS_SECRET}

COPY . .
RUN set -eu && \
Expand Down
4 changes: 4 additions & 0 deletions build/redhat/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
#
FROM golang:1.22-alpine AS builder

ARG WAYBACK_IPFS_TARGET
ARG WAYBACK_IPFS_APIKEY
ARG WAYBACK_IPFS_SECRET

RUN apk update && apk add --no-cache build-base ca-certificates git
# Required by statically linked binary with OpenSSL
# RUN apk add linux-headers

ENV WAYBACK_IPFS_TARGET ${WAYBACK_IPFS_TARGET}
ENV WAYBACK_IPFS_APIKEY ${WAYBACK_IPFS_APIKEY}
ENV WAYBACK_IPFS_SECRET ${WAYBACK_IPFS_SECRET}

WORKDIR /go/src/app

Expand Down
4 changes: 2 additions & 2 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func TestIPFSTarget(t *testing.T) {
os.Clearenv()
os.Setenv("WAYBACK_IPFS_TARGET", test.userTarget)
os.Setenv("WAYBACK_IPFS_APIKEY", test.userApikey)
IPFSToken = test.token
IPFSApikey = test.token

parser := NewParser()
opts, err := parser.ParseEnvironmentVariables()
Expand Down Expand Up @@ -337,7 +337,7 @@ func TestIPFSApikey(t *testing.T) {
os.Clearenv()
os.Setenv("WAYBACK_IPFS_TARGET", test.userTarget)
os.Setenv("WAYBACK_IPFS_APIKEY", test.userApikey)
IPFSToken = test.token
IPFSApikey = test.token

parser := NewParser()
opts, err := parser.ParseEnvironmentVariables()
Expand Down
24 changes: 15 additions & 9 deletions config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ const (
)

var (
IPFSToken = ""
IPFSTarget = "web3storage"
IPFSTarget = ""
IPFSApikey = ""
IPFSSecret = ""

defStorageDir = path.Join(os.TempDir(), "reduxer")
defOnionRemotePorts = []int{80}
Expand Down Expand Up @@ -443,25 +444,30 @@ func (o *Options) IPFSMode() string {
}

// IPFSTarget returns which IPFS pinning service to use.
// It returns a managed IPFS credential if env `WAYBACK_IPFS_TARGET` empty.
func (o *Options) IPFSTarget() string {
if IPFSToken != "" {
return IPFSTarget
if o.ipfs.target != "" {
return o.ipfs.target
}
return o.ipfs.target
return IPFSTarget
}

// IPFSApiKey returns the apikey of the IPFS pinning service.
// It returns a managed IPFS credential if env `WAYBACK_IPFS_APIKEY` empty.
func (o *Options) IPFSApikey() string {
if o.ipfs.apikey == "" {
return IPFSToken
if o.ipfs.apikey != "" {
return o.ipfs.apikey
}
return o.ipfs.apikey
return IPFSApikey
}

// IPFSSecret returns the secret of the IPFS pinning service.
// It returns a managed IPFS credential if env `WAYBACK_IPFS_SECRET` empty.
func (o *Options) IPFSSecret() string {
return o.ipfs.secret
if o.ipfs.secret != "" {
return o.ipfs.secret
}
return IPFSSecret
}

// UseTor returns whether to use the Tor proxy when snapshot webpage.
Expand Down
10 changes: 10 additions & 0 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@ variable "GO_VERSION" {
default = "1.22"
}

variable "WAYBACK_IPFS_TARGET" {
default = ""
}

variable "WAYBACK_IPFS_APIKEY" {
default = ""
}

variable "WAYBACK_IPFS_SECRET" {
default = ""
}

// GitHub reference as defined in GitHub Actions (eg. refs/head/master))
variable "GITHUB_REF" {
default = ""
Expand All @@ -15,7 +23,9 @@ variable "GITHUB_REF" {
target "_common" {
args = {
GO_VERSION = GO_VERSION
WAYBACK_IPFS_TARGET = WAYBACK_IPFS_TARGET
WAYBACK_IPFS_APIKEY = WAYBACK_IPFS_APIKEY
WAYBACK_IPFS_SECRET = WAYBACK_IPFS_SECRET
}
}

Expand Down

0 comments on commit 3a5b1d0

Please sign in to comment.