From 7b1492f32788b621c6f9c571540b99ce22adf5b6 Mon Sep 17 00:00:00 2001 From: Milo Schwartz Date: Wed, 29 Jan 2025 22:23:03 -0500 Subject: [PATCH] add cicd --- .github/workflows/cicd.yml | 50 ++++++++++++++++++++++++++++++++++++++ Makefile | 24 ++++++++++++------ 2 files changed, 66 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/cicd.yml diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml new file mode 100644 index 0000000..dec756a --- /dev/null +++ b/.github/workflows/cicd.yml @@ -0,0 +1,50 @@ +name: CI/CD Pipeline + +on: + push: + tags: + - "*" + +jobs: + release: + name: Build and Release + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + + - name: Extract tag name + id: get-tag + run: echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV + + - name: Install Go + uses: actions/setup-go@v4 + with: + go-version: 1.23.1 + + - name: Build and push Docker images + run: | + TAG=${{ env.TAG }} + make docker-build-release tag=$TAG + + - name: Build binaries + run: | + make go-build-release + + - name: Upload artifacts from /bin + uses: actions/upload-artifact@v3 + with: + name: binaries + path: bin/ + + diff --git a/Makefile b/Makefile index 0f0aa39..3dbb196 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,14 @@ all: build push +docker-build-release: + @if [ -z "$(tag)" ]; then \ + echo "Error: tag is required. Usage: make build-all tag="; \ + exit 1; \ + fi + docker buildx build --platform linux/arm64,linux/amd64 -t fosrl/newt:latest -f Dockerfile --push . + docker buildx build --platform linux/arm64,linux/amd64 -t fosrl/newt:$(tag) -f Dockerfile --push . + build: docker build -t fosrl/newt:latest . @@ -13,14 +21,14 @@ test: local: CGO_ENABLED=0 go build -o newt -all_arches: - CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o newt_linux_arm64 - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o newt_linux_amd64 - CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o newt_darwin_arm64 - CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o newt_darwin_amd64 - CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o newt_windows_amd64.exe - CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -o newt_freebsd_amd64 - CGO_ENABLED=0 GOOS=freebsd GOARCH=arm64 go build -o newt_freebsd_arm64 +go-build-release: + CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o bin/newt_linux_arm64 + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/newt_linux_amd64 + CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o bin/newt_darwin_arm64 + CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o bin/newt_darwin_amd64 + CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o bin/newt_windows_amd64.exe + CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -o bin/newt_freebsd_amd64 + CGO_ENABLED=0 GOOS=freebsd GOARCH=arm64 go build -o bin/newt_freebsd_arm64 clean: rm newt