Skip to content

Commit

Permalink
proxyscotch
Browse files Browse the repository at this point in the history
  • Loading branch information
Tob1as committed Nov 21, 2024
1 parent ca5dd2a commit d7c9417
Show file tree
Hide file tree
Showing 2 changed files with 165 additions and 0 deletions.
113 changes: 113 additions & 0 deletions .github/workflows/build_docker_images-proxyscotch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
name: 'build docker images: static cURL'

on:
#push:
# branches:
# - 'main'
# - 'master'
# paths:
# - 'proxyscotch.scratch.Dockerfile'
# - '.github/workflows/build_docker_images-proxyscotch.yaml'
workflow_dispatch:
schedule:
- cron: '30 5 10 * *' # At 05:30 on day-of-month 10.

defaults:
run:
shell: bash

jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Shell-Script
id: script
run: |
BUILD_DATE="$(date -u +'%Y-%m-%dT%H:%M:%SZ')"
BUILD_DATE_NUMERIC="${BUILD_DATE//[^[:digit:]]/}"
COMMIT_HASH=${GITHUB_SHA::8}
GIT_URL=$(echo "${GITHUB_SERVER_URL}" | awk -F/ '{print $3}' | sed 's/\/*$//')
GIT_URL=$(echo "$GIT_URL" | sed 's/github\.com/ghcr\.io/g') # GIT_URL switch to ghcr.io registry for GitHub
GIT_REPO=${GITHUB_REPOSITORY,,}
GIT_REPO_SHORT=${GIT_REPO#*/}
GIT_REPO_SHORT=${GIT_REPO_SHORT#"docker-"}
DOCKER_REPO=${{ secrets.DOCKER_USERNAME }}/${GIT_REPO_SHORT}
REDHAT_QUAY_REPO=${{ secrets.REDHAT_QUAY_USERNAME }}/${GIT_REPO_SHORT}
#echo "ENVs: BUILD_DATE=${BUILD_DATE}, BUILD_DATE_NUMERIC=${BUILD_DATE_NUMERIC}, COMMIT_HASH=${COMMIT_HASH}, GIT_URL=${GIT_URL}, GIT_REPO=${GIT_REPO}"
# Set output parameters to action.
echo "build_date=${BUILD_DATE}" >> "$GITHUB_OUTPUT"
echo "build_date_numeric=${BUILD_DATE_NUMERIC}" >> "$GITHUB_OUTPUT"
echo "commit_hash=${COMMIT_HASH}" >> "$GITHUB_OUTPUT"
echo "git_url=${GIT_URL}" >> "$GITHUB_OUTPUT"
echo "git_repo=${GIT_REPO}" >> "$GITHUB_OUTPUT"
echo "docker_repo=${DOCKER_REPO}" >> "$GITHUB_OUTPUT"
echo "redhat_quay_repo=${REDHAT_QUAY_REPO}" >> "$GITHUB_OUTPUT"
# Proxyscotch
PROXYSCOTCH_VERSION=$(wget -qO- https://api.github.com/repos/hoppscotch/proxyscotch/releases/latest | grep 'tag_name' | cut -d\" -f4)
echo "PROXYSCOTCH_VERSION=${PROXYSCOTCH_VERSION}"
echo "PROXYSCOTCH_VERSION=${PROXYSCOTCH_VERSION}" >> "$GITHUB_OUTPUT"
- name: Set up QEMU
id: qemu
uses: docker/setup-qemu-action@v3
with:
image: tonistiigi/binfmt:latest
platforms: all

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3

- name: Login to GIT Container Registry
uses: docker/login-action@v3
with:
registry: ${{ steps.script.outputs.git_url }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Login to DockerHub Container Registry
uses: docker/login-action@v3
with:
registry: docker.io
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Login to RED HAT Quay.io Container Registry
uses: docker/login-action@v3
with:
registry: quay.io
username: ${{ secrets.REDHAT_QUAY_USERNAME }}
password: ${{ secrets.REDHAT_QUAY_PASSWORD }}

- name: Build
uses: docker/build-push-action@v6
with:
builder: ${{ steps.buildx.outputs.name }}
context: .
file: ./proxyscotch.scratch.Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/ppc64le,linux/riscv64
push: true
build-args: |
BUILD_DATE=${{steps.script.outputs.build_date}}
VCS_REF=${{steps.script.outputs.commit_hash}}
VERSION=${{steps.script.outputs.proxyscotch_version}}
tags: |
docker.io/${{steps.script.outputs.docker_repo}}:proxyscotch
docker.io/${{steps.script.outputs.docker_repo}}:proxyscotch-${{steps.script.outputs.proxyscotch_version}}
quay.io/${{steps.script.outputs.redhat_quay_repo}}:proxyscotch
${{steps.script.outputs.git_url}}/${{steps.script.outputs.git_repo}}:proxyscotch
#- name: Docker Hub Description
# uses: peter-evans/dockerhub-description@v4
# with:
# username: ${{ secrets.DOCKER_USERNAME }}
# password: ${{ secrets.DOCKER_PASSWORD }}
# repository: ${{steps.script.outputs.docker_repo}}
# short-description: ${{ github.event.repository.description }}
# readme-filepath: README.md
52 changes: 52 additions & 0 deletions proxyscotch.scratch.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
FROM golang:alpine AS builder

ARG VERSION

# Proxyscotch
RUN \
apk add --no-cache git ; \
VERSION=${VERSION:-$(wget -qO- https://api.github.com/repos/hoppscotch/proxyscotch/tags | grep 'name' | cut -d\" -f4 | sort -r | head -1)} ; \
echo "Proxyscotch Version = ${VERSION}" ; \
BUILD_OS=$(go env GOOS) ; \
BUILD_ARCH=$(go env GOARCH) ; \
cd /etc ; \
git clone --branch ${VERSION} --single-branch https://github.com/hoppscotch/proxyscotch.git ./proxyscotch ; \
cd /etc/proxyscotch ; \
# prepare for other arch https://github.com/hoppscotch/proxyscotch/blob/master/build.sh#L329
sed -i "s/amd64/${BUILD_ARCH}/" build.sh ; \
./build.sh ${BUILD_OS} server ; \
cp ./out/${BUILD_OS}-server/proxyscotch-server-${BUILD_OS}-${BUILD_ARCH}-${VERSION} /usr/local/bin/proxyscotch ; \
proxyscotch --help

# CAs
#COPY *.crt /usr/local/share/ca-certificates/
#RUN \
# update-ca-certificates


FROM scratch

ARG VERSION
ARG VCS_REF
ARG BUILD_DATE

LABEL org.opencontainers.image.title="Proxyscotch" \
org.opencontainers.image.vendor="" \
org.opencontainers.image.authors="" \
org.opencontainers.image.version="${VERSION}" \
org.opencontainers.image.created="${BUILD_DATE}" \
org.opencontainers.image.revision="${VCS_REF}" \
org.opencontainers.image.description="A simple proxy server created for Hoppscotch <https://github.com/hoppscotch/hoppscotch>." \
org.opencontainers.image.documentation="https://github.com/hoppscotch/proxyscotch" \
org.opencontainers.image.base.name="scratch" \
org.opencontainers.image.licenses="MIT" \
org.opencontainers.image.url="https://github.com/Tob1as/docker-tools" \
org.opencontainers.image.source="https://github.com/hoppscotch/proxyscotch"

COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder --chown=1000:100 /usr/local/bin/proxyscotch /usr/local/bin/proxyscotch

EXPOSE 9159/tcp
USER 1000:100
ENTRYPOINT ["proxyscotch"]
CMD ["--host", "0.0.0.0:9159"]

0 comments on commit d7c9417

Please sign in to comment.