Skip to content

Commit

Permalink
Added support for multi-arch building (#9)
Browse files Browse the repository at this point in the history
Also, modified image tagging to support forked repos.
  • Loading branch information
bearlike authored Nov 9, 2023
1 parent d2094b9 commit bebf956
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 27 deletions.
55 changes: 30 additions & 25 deletions .github/workflows/build-push.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: "Docker Build & Push"

on:
push:
branches:
Expand All @@ -9,23 +10,30 @@ on:
description: "Version of image tag (after ':')"
required: true


jobs:
export_tag:
name: "Generate Docker image tag"
runs-on: ubuntu-latest
env:
IMAGE_TAG_BASE: ghcr.io/david-lor/portforward
IMAGE_TAG_VERSION_FILE: /tmp/image_tag_version.txt
outputs:
image_tag: ${{ steps.image_tag.outputs.image_tag }}

steps:
- name: "Lowercase GitHub user and repo"
id: lowercase_repo
run: |
echo "GH_USER=${GITHUB_REPOSITORY_OWNER,,}" >> $GITHUB_ENV
echo "GH_REPO=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
# Get just the repository name, not the owner/name format
REPO_NAME="${GITHUB_REPOSITORY##*/}"
echo "REPO_NAME=${REPO_NAME,,}" >> $GITHUB_ENV
- name: "Set IMAGE_TAG_BASE and IMAGE_TAG_VERSION_FILE"
run: |
echo "IMAGE_TAG_BASE=ghcr.io/${{ env.GH_USER }}/${{ env.REPO_NAME }}" >> $GITHUB_ENV
echo "IMAGE_TAG_VERSION_FILE=/tmp/image_tag_version.txt" >> $GITHUB_ENV
- name: "Identify image tag version (from push to main)"
if: ${{ github.ref == 'refs/heads/main' }}
run: echo latest > ${{ env.IMAGE_TAG_VERSION_FILE }}
run: echo "latest" > ${{ env.IMAGE_TAG_VERSION_FILE }}
- name: "Set image tag version (from workflow dispatch)"
if: ${{ github.event.inputs.image_tag_version }}
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.image_tag_version }}
run: echo ${{ github.event.inputs.image_tag_version }} > ${{ env.IMAGE_TAG_VERSION_FILE }}
- name: "Fetch exported image tag version"
id: image_tag_version
Expand All @@ -34,37 +42,34 @@ jobs:
path: ${{ env.IMAGE_TAG_VERSION_FILE }}
- name: "Format complete image tag"
id: image_tag
run: |-
run: |
FULL_TAG="${{ env.IMAGE_TAG_BASE }}:${{ steps.image_tag_version.outputs.content }}"
echo "Full tag: $FULL_TAG"
echo "::set-output name=image_tag::$FULL_TAG"
build_push:
name: "Docker Build & Push"
runs-on: ubuntu-latest
needs:
- export_tag
env:
IMAGE_TAG: ${{ needs.export_tag.outputs.image_tag }}

needs: export_tag
steps:
# Setup
- name: "Checkout"
uses: actions/checkout@master
uses: actions/checkout@v2
with:
fetch-depth: 1

# Registry login
- name: "Set up QEMU"
uses: docker/setup-qemu-action@v1
- name: "Set up Docker Buildx"
uses: docker/setup-buildx-action@v1
- name: "Login to GitHub Container Registry"
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Build & Push
- name: "Docker build"
run: docker build . -t ${{ env.IMAGE_TAG }}
- name: "Docker push"
run: docker push ${{ env.IMAGE_TAG }}
- name: "Build and push"
uses: docker/build-push-action@v2
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ needs.export_tag.outputs.image_tag }}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Docker image for setting up one or multiple TCP ports forwarding, using socat.
- The ports mappings are set with environment variables, whose key must start with `PORT`, and then can have any name.
- Each environment variable can hold only one mapping. For setting multiple ports, many variables must be defined.
- The format of environment variable values is: `LOCAL_PORT:REMOTE_HOST:REMOTE_PORT` (LOCAL_PORT is optional, if not given, will use the same port as REMOTE_PORT)
- If you're using a fork of this repo, you can build and pull your own images

### Example

Expand Down Expand Up @@ -43,8 +44,7 @@ The environment variable `SOCKS_PROXY` can be used for specifying the `ip:port`
This will be applied to ALL the port mappings on the current container.

## TODO

- Multiarch images
- [X] Multiarch images

## Changelog

Expand Down

0 comments on commit bebf956

Please sign in to comment.