From 3a0123dad8ca44baf70d8eb5db04a6725795e49d Mon Sep 17 00:00:00 2001 From: Cody Baker Date: Sat, 17 Feb 2024 21:36:32 +0000 Subject: [PATCH] add docker build --- .github/workflows/go.yml | 26 +++++++++++++++++++++++++- ci/Dockerfile | 5 +++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 ci/Dockerfile diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 1ce3ed6..e9f6563 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -15,6 +15,9 @@ jobs: build: runs-on: ubuntu-latest + permissions: + packages: write + contents: read steps: - uses: actions/checkout@v4 @@ -45,4 +48,25 @@ jobs: files: | shellyctl_linux_amd64 shellyctl_linux_arm64 - shellyctl_windows_arm64 \ No newline at end of file + shellyctl_windows_arm64 + + - name: Build image + run: docker build . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}" + - name: Log in to registry + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin + + - name: Push image + run: | + IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME + + IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') + + VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') + + [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') + + [ "$VERSION" == "main" ] && VERSION=latest + echo IMAGE_ID=$IMAGE_ID + echo VERSION=$VERSION + docker tag $IMAGE_NAME $IMAGE_ID:$VERSION + docker push $IMAGE_ID:$VERSION \ No newline at end of file diff --git a/ci/Dockerfile b/ci/Dockerfile new file mode 100644 index 0000000..d2b1798 --- /dev/null +++ b/ci/Dockerfile @@ -0,0 +1,5 @@ +FROM scratch + +COPY ./shellyctl_linux_amd64 /bin/shellyctl_linux_amd64 + +ENTRYPOINT [ "/bin/shellyctl_linux_amd64" ] \ No newline at end of file