diff --git a/.github/workflows/docker-build-dev.yml b/.github/workflows/docker-build-dev.yml index 147108e..50ff8d4 100644 --- a/.github/workflows/docker-build-dev.yml +++ b/.github/workflows/docker-build-dev.yml @@ -10,16 +10,53 @@ env: IMAGE_NAME: ${{ github.repository }} jobs: - build: + build-binaries: + runs-on: ubuntu-latest + strategy: + matrix: + arch: [amd64, arm64] + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.24.0' + check-latest: true + + - name: Build binary for ${{ matrix.arch }} + run: | + GOOS=linux GOARCH=${{ matrix.arch }} make build + + - name: Upload binary artifact + uses: actions/upload-artifact@v4 + with: + name: gozargah-node-linux-${{ matrix.arch }} + path: gozargah-node-linux-${{ matrix.arch }} + retention-days: 1 + + build-and-push-docker: + needs: build-binaries runs-on: ubuntu-latest permissions: contents: read packages: write - steps: - name: Checkout repository uses: actions/checkout@v4 + - name: Download all binary artifacts + uses: actions/download-artifact@v4 + + - name: Move binaries to correct location + run: | + ls -la + chmod +x */gozargah-node-linux-* + mkdir -p binaries + find . -name "gozargah-node-linux-*" -type f -exec cp {} binaries/ \; + ls -la binaries/ + - name: Login to Docker Hub uses: docker/login-action@v2 with: @@ -33,6 +70,9 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -46,12 +86,12 @@ jobs: uses: docker/build-push-action@v5 with: context: . + file: ./Dockerfile.multi platforms: linux/amd64,linux/arm64 push: true tags: | m03ed/gozargah-node:${{ github.ref_name }} ghcr.io/m03ed/gozargah-node:${{ github.ref_name }} - labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha - cache-to: type=gha,mode=max \ No newline at end of file + cache-to: type=gha,mode=max diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 0c48957..4d481ff 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -9,16 +9,53 @@ env: IMAGE_NAME: ${{ github.repository }} jobs: - build: + build-binaries: + runs-on: ubuntu-latest + strategy: + matrix: + arch: [amd64, arm64] + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.24.0' + check-latest: true + + - name: Build binary for ${{ matrix.arch }} + run: | + GOOS=linux GOARCH=${{ matrix.arch }} make build + + - name: Upload binary artifact + uses: actions/upload-artifact@v4 + with: + name: gozargah-node-linux-${{ matrix.arch }} + path: gozargah-node-linux-${{ matrix.arch }} + retention-days: 1 + + build-and-push-docker: + needs: build-binaries runs-on: ubuntu-latest permissions: contents: read packages: write - steps: - name: Checkout repository uses: actions/checkout@v4 + - name: Download all binary artifacts + uses: actions/download-artifact@v4 + + - name: Move binaries to correct location + run: | + ls -la + chmod +x */gozargah-node-linux-* + mkdir -p binaries + find . -name "gozargah-node-linux-*" -type f -exec cp {} binaries/ \; + ls -la binaries/ + - name: Login to Docker Hub uses: docker/login-action@v2 with: @@ -32,6 +69,9 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -56,9 +96,10 @@ jobs: uses: docker/build-push-action@v5 with: context: . + file: ./Dockerfile.multi platforms: linux/amd64,linux/arm64 push: true tags: ${{ env.DOCKER_TAGS }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha - cache-to: type=gha,mode=max \ No newline at end of file + cache-to: type=gha,mode=max diff --git a/Dockerfile b/Dockerfile index 6ef7075..4784f70 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.24.0 as builder +FROM golang:1.24.0 as base WORKDIR /app COPY go.mod . @@ -6,7 +6,7 @@ COPY go.sum . RUN go mod download COPY . . -COPY . . +FROM base as builder ARG TARGETOS ARG TARGETARCH RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o main -ldflags="-w -s" . diff --git a/Dockerfile.multi b/Dockerfile.multi new file mode 100644 index 0000000..986b447 --- /dev/null +++ b/Dockerfile.multi @@ -0,0 +1,16 @@ +FROM alpine:latest + +RUN apk update && apk add --no-cache make + +RUN mkdir /app +WORKDIR /app + +COPY Makefile . + +ARG TARGETARCH +COPY gozargah-node-linux-${TARGETARCH} /app/main +RUN chmod +x /app/main + +RUN make install_xray + +ENTRYPOINT ["./main", "serve"] \ No newline at end of file