Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Tob1as committed Dec 1, 2024
1 parent 6df81f4 commit 5dd5adf
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 35 deletions.
36 changes: 17 additions & 19 deletions .github/workflows/build_docker_images-c-mqtt-forwarder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,23 @@ jobs:
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}"
GITHUB_REPO=${GITHUB_REPOSITORY,,}
GITHUB_REPO_SHORT=${GITHUB_REPO#*/}
GITHUB_REPO_SHORT=${GITHUB_REPO_SHORT#"docker-"}
DOCKER_REPO=${{ secrets.DOCKER_USERNAME }}/${GITHUB_REPO_SHORT}
REDHAT_QUAY_REPO=${{ secrets.REDHAT_QUAY_USERNAME }}/${GITHUB_REPO_SHORT}
# 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 "github_repo=${GITHUB_REPO}" >> "$GITHUB_OUTPUT"
echo "docker_repo=${DOCKER_REPO}" >> "$GITHUB_OUTPUT"
echo "redhat_quay_repo=${REDHAT_QUAY_REPO}" >> "$GITHUB_OUTPUT"
# c-mqtt-forwarder
#C_MQTT_FORWARDER_VERSION=$(git ls-remote --tags "https://git.ypbind.de/repository/c-mqtt-forwarder.git" | awk -F/ '{print $NF}' | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -n1)
#C_MQTT_FORWARDER_VERSION=$(curl -s "https://git.ypbind.de/cgit/c-mqtt-forwarder/refs/" | grep -oE '/tag/\?h=[0-9]+\.[0-9]+\.[0-9]+' | sed -E 's|.*/tag/\?h=([0-9]+\.[0-9]+\.[0-9]+)|\1|' | sort -V | tail -n1)
C_MQTT_FORWARDER_VERSION="1.0.0"
echo "c_mqtt_forwarder_version=${C_MQTT_FORWARDER_VERSION}" >> "$GITHUB_OUTPUT"
Expand All @@ -61,24 +58,24 @@ jobs:

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

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

- name: Login to DockerHub Container Registry
uses: docker/login-action@v3
- name: Login to DockerHub
uses: docker/login-action@v2
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
uses: docker/login-action@v2
with:
registry: quay.io
username: ${{ secrets.REDHAT_QUAY_USERNAME }}
Expand All @@ -98,8 +95,9 @@ jobs:
VERSION=${{steps.script.outputs.c_mqtt_forwarder_version}}
tags: |
docker.io/${{steps.script.outputs.docker_repo}}:c-mqtt-forwarder
docker.io/${{steps.script.outputs.docker_repo}}:c-mqtt-forwarder-${{steps.script.outputs.c_mqtt_forwarder_version}}
quay.io/${{steps.script.outputs.redhat_quay_repo}}:c-mqtt-forwarder
${{steps.script.outputs.git_url}}/${{steps.script.outputs.git_repo}}:c-mqtt-forwarder
ghcr.io/${{steps.script.outputs.github_repo}}:c-mqtt-forwarder
#- name: Docker Hub Description
# uses: peter-evans/dockerhub-description@v4
Expand Down
27 changes: 15 additions & 12 deletions .github/workflows/build_docker_images-mqtt-forwarder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Shell-Script
id: script
Expand All @@ -35,28 +35,30 @@ jobs:
DOCKER_REPO=${{ secrets.DOCKER_USERNAME }}/${GITHUB_REPO_SHORT}
REDHAT_QUAY_REPO=${{ secrets.REDHAT_QUAY_USERNAME }}/${GITHUB_REPO_SHORT}
# Set output parameters to github action.
echo ::set-output name=build_date::${BUILD_DATE}
echo ::set-output name=build_date_numeric::${BUILD_DATE_NUMERIC}
echo ::set-output name=commit_hash::${COMMIT_HASH}
echo ::set-output name=github_repo::${GITHUB_REPO}
echo ::set-output name=docker_repo::${DOCKER_REPO}
echo ::set-output name=redhat_quay_repo::${REDHAT_QUAY_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 "github_repo=${GITHUB_REPO}" >> "$GITHUB_OUTPUT"
echo "docker_repo=${DOCKER_REPO}" >> "$GITHUB_OUTPUT"
echo "redhat_quay_repo=${REDHAT_QUAY_REPO}" >> "$GITHUB_OUTPUT"
# mqtt-forwarder
#MQTT_FORWARDER_VERSION=$(git ls-remote --tags "https://git.ypbind.de/repository/mqtt-forwarder.git" | awk -F/ '{print $NF}' | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -n1)
#MQTT_FORWARDER_VERSION=$(curl -s "https://git.ypbind.de/cgit/mqtt-forwarder/refs/" | grep -oE '/tag/\?h=[0-9]+\.[0-9]+\.[0-9]+' | sed -E 's|.*/tag/\?h=([0-9]+\.[0-9]+\.[0-9]+)|\1|' | sort -V | tail -n1)
MQTT_FORWARDER_VERSION="1.1.1"
echo "mqtt_forwarder_version=${MQTT_FORWARDER_VERSION}" >> "$GITHUB_OUTPUT"
- name: Set up QEMU
id: qemu
uses: docker/setup-qemu-action@v2
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@v2
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
Expand All @@ -80,7 +82,7 @@ jobs:
password: ${{ secrets.REDHAT_QUAY_PASSWORD }}

- name: Build
uses: docker/build-push-action@v3
uses: docker/build-push-action@v6
with:
builder: ${{ steps.buildx.outputs.name }}
context: .
Expand All @@ -93,11 +95,12 @@ jobs:
VERSION=${{steps.script.outputs.mqtt_forwarder_version}}
tags: |
docker.io/${{steps.script.outputs.docker_repo}}:mqtt-forwarder
docker.io/${{steps.script.outputs.docker_repo}}:mqtt-forwarder-${{steps.script.outputs.mqtt_forwarder_version}}
quay.io/${{steps.script.outputs.redhat_quay_repo}}:mqtt-forwarder
ghcr.io/${{steps.script.outputs.github_repo}}:mqtt-forwarder
#- name: Docker Hub Description
# uses: peter-evans/dockerhub-description@v3
# uses: peter-evans/dockerhub-description@v4
# with:
# username: ${{ secrets.DOCKER_USERNAME }}
# password: ${{ secrets.DOCKER_PASSWORD }}
Expand Down
2 changes: 1 addition & 1 deletion c-mqtt-forwarder.alpine.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ COPY <<EOF /etc/mqtt-forwarder/config.json
EOF


FROM alpine:latest
FROM alpine:latest AS production

ARG VCS_REF
ARG BUILD_DATE
Expand Down
4 changes: 1 addition & 3 deletions mqtt-forwarder.scratch.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ RUN \
go build -o ${GOPATH}/bin/mqtt-forwarder . ; \
${GOPATH}/bin/mqtt-forwarder --version

#FROM alpine:latest
FROM scratch
FROM scratch AS production
ARG VCS_REF
ARG BUILD_DATE
ARG VERSION
Expand All @@ -31,7 +30,6 @@ LABEL org.opencontainers.image.title="mqtt-forwarder" \
org.opencontainers.image.licenses="GPL-3.0" \
org.opencontainers.image.url="https://github.com/Tob1as/docker-tools" \
org.opencontainers.image.source="https://git.ypbind.de/cgit/mqtt-forwarder/"
#RUN apk add --no-cache ca-certificates
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=builder --chown=1000:1000 /go/bin/mqtt-forwarder /usr/local/bin/mqtt-forwarder
COPY --from=builder --chown=1000:1000 /go/src/mqtt-forwarder/example/config.ini /etc/mqtt-forwarder/config.ini
Expand Down

0 comments on commit 5dd5adf

Please sign in to comment.