diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml new file mode 100644 index 0000000..8d223d0 --- /dev/null +++ b/.github/workflows/cicd.yml @@ -0,0 +1,49 @@ +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 9a29170..dadb9b3 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/gerbil:latest -f Dockerfile --push . + docker buildx build --platform linux/arm64,linux/amd64 -t fosrl/gerbil:$(tag) -f Dockerfile --push . + build: docker build -t fosrl/gerbil:latest . @@ -13,9 +21,9 @@ test: local: CGO_ENABLED=0 GOOS=linux go build -o gerbil -release: +go-build-release: CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o bin/gerbil_linux_arm64 CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/gerbil_linux_amd64 clean: - rm gerbil \ No newline at end of file + rm gerbil