[Feat] ✨ Add Github Action To Build Binary & Docker image #3 #4
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build GPU Docker API | |
| on: | |
| push: | |
| tags: | |
| - v* | |
| jobs: | |
| build: | |
| name: build | |
| runs-on: ubuntu-latest | |
| if: github.repository == 'XShengTech/gpu-docker-api' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: 'stable' | |
| check-latest: true | |
| - name: Build binary | |
| run: | | |
| BRANCH=$(git rev-parse --abbrev-ref HEAD) | |
| VERSION=$(git describe --tags | cut -d'-' -f1) | |
| COMMIT=$(git rev-parse --short HEAD) | |
| GO_VERSION=$(go env GOVERSION) | |
| BUILD_TIME=$(date +%FT%T%z) | |
| GOOS=linux GOARCH=amd64 go build -ldflags="-s -w -X main.BRANCH=${BRANCH} -X main.VERSION=${VERSION} -X main.COMMIT=${COMMIT} -X main.GoVersion=${GO_VERSION} -X main.BuildTime=${BUILD_TIME}" -trimpath -o gpu-docker-api cmd/gpu-docker-api/main.go && tar -zcvf gpu-docker-api-linux-amd64.tar.gz gpu-docker-api | |
| - name: Create Release and Upload Release Asset | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| files: | | |
| gpu-docker-api-linux-amd64.tar.gz | |
| docker-build: | |
| name: docker-build | |
| runs-on: ubuntu-latest | |
| permissions: | |
| packages: write | |
| contents: read | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Setup timezone | |
| uses: zcong1993/setup-timezone@master | |
| with: | |
| timezone: Asia/Shanghai | |
| - name: Login to DockerHub | |
| uses: docker/login-action@v2 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v2 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| - name: Build and push | |
| uses: docker/build-push-action@v4 | |
| with: | |
| platforms: linux/amd64 | |
| context: . | |
| file: ./Dockerfile | |
| push: true | |
| tags: | | |
| docker.io/xshengtech/gpu-docker-api:${{ github.ref_name }} | |
| docker.io/xshengtech/gpu-docker-api:latest |