From 5ca8f5a8ec5e300af39b26d44be1474c3e7afa74 Mon Sep 17 00:00:00 2001 From: Raymond Jacobson Date: Wed, 21 May 2025 13:32:37 -0400 Subject: [PATCH 1/6] Add github action --- .github/workflows/docker-build.yml | 32 ++++++++++++++++++++++++++++++ Dockerfile | 21 ++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 .github/workflows/docker-build.yml create mode 100644 Dockerfile diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 00000000..ec4f2c2a --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -0,0 +1,32 @@ +name: Build and Push Docker Image + +on: + push: + branches: [ rj-docker-build ] + pull_request: + branches: [ main ] + +jobs: + build-and-push: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to DockerHub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: audius/api:latest + cache-from: type=registry,ref=audius/api:buildcache + cache-to: type=registry,ref=audius/api:buildcache,mode=max \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..b55d0f01 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +FROM golang:1.22-alpine AS builder + +WORKDIR /app + +COPY go.mod go.sum ./ + +RUN go mod download + +COPY . . + +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bridge-amd64 main.go + +FROM alpine:latest + +WORKDIR /app + +COPY --from=builder /app/bridge-amd64 /bin/bridge + +EXPOSE 1323 + +CMD ["bridge"] From 004c4e1e0831299b7875554966ac721e2f8714ee Mon Sep 17 00:00:00 2001 From: Raymond Jacobson Date: Wed, 21 May 2025 13:34:06 -0400 Subject: [PATCH 2/6] Upgrade go version --- .github/workflows/docker-build.yml | 2 +- Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index ec4f2c2a..86fc8413 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -2,7 +2,7 @@ name: Build and Push Docker Image on: push: - branches: [ rj-docker-build ] + branches: [ main ] pull_request: branches: [ main ] diff --git a/Dockerfile b/Dockerfile index b55d0f01..06c8d30b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.22-alpine AS builder +FROM golang:1.24-alpine AS builder WORKDIR /app From 884c8b6fb964f947579d682bd284bed0b9c1079c Mon Sep 17 00:00:00 2001 From: Raymond Jacobson Date: Wed, 21 May 2025 13:37:35 -0400 Subject: [PATCH 3/6] Improve build --- .../workflows/{docker-build.yml => build.yml} | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) rename .github/workflows/{docker-build.yml => build.yml} (63%) diff --git a/.github/workflows/docker-build.yml b/.github/workflows/build.yml similarity index 63% rename from .github/workflows/docker-build.yml rename to .github/workflows/build.yml index 86fc8413..bd9f969a 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/build.yml @@ -2,9 +2,7 @@ name: Build and Push Docker Image on: push: - branches: [ main ] - pull_request: - branches: [ main ] + branches: [ '**' ] jobs: build-and-push: @@ -22,11 +20,21 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Extract metadata for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: audius/api + tags: | + type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }} + type=sha,format=short + - name: Build and push uses: docker/build-push-action@v5 with: context: . push: true - tags: audius/api:latest + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} cache-from: type=registry,ref=audius/api:buildcache cache-to: type=registry,ref=audius/api:buildcache,mode=max \ No newline at end of file From 4307bd311cb6daaaac1f500f69a449f64dc69431 Mon Sep 17 00:00:00 2001 From: Raymond Jacobson Date: Wed, 21 May 2025 13:46:21 -0400 Subject: [PATCH 4/6] Use full sha --- .github/workflows/build.yml | 2 +- .github/workflows/docker-build.yml | 40 ++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/docker-build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bd9f969a..b46913c9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,7 +27,7 @@ jobs: images: audius/api tags: | type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }} - type=sha,format=short + type=sha - name: Build and push uses: docker/build-push-action@v5 diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 00000000..168bc7a0 --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -0,0 +1,40 @@ +name: Build and Push Docker Image + +on: + push: + branches: [ '**' ] + +jobs: + build-and-push: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to DockerHub + uses: docker/login-action@v3 + with: + username: audiusci + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Extract metadata for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: audius/api + tags: | + type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }} + type=sha + + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=registry,ref=audius/api:buildcache + cache-to: type=registry,ref=audius/api:buildcache,mode=max \ No newline at end of file From 1bccc96785503f0b853e55f2ddb9b5d4c32cf98f Mon Sep 17 00:00:00 2001 From: Raymond Jacobson Date: Wed, 21 May 2025 13:58:11 -0400 Subject: [PATCH 5/6] Fix sha --- .github/workflows/build.yml | 16 +++++------- .github/workflows/docker-build.yml | 40 ------------------------------ 2 files changed, 6 insertions(+), 50 deletions(-) delete mode 100644 .github/workflows/docker-build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b46913c9..0bbe94d2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,21 +20,17 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Extract metadata for Docker - id: meta - uses: docker/metadata-action@v5 - with: - images: audius/api - tags: | - type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }} - type=sha + - name: Get full SHA + id: sha + run: echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT - name: Build and push uses: docker/build-push-action@v5 with: context: . push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} + tags: | + audius/api:latest,enable=${{ github.ref == 'refs/heads/main' }} + audius/api:${{ steps.sha.outputs.sha }} cache-from: type=registry,ref=audius/api:buildcache cache-to: type=registry,ref=audius/api:buildcache,mode=max \ No newline at end of file diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml deleted file mode 100644 index 168bc7a0..00000000 --- a/.github/workflows/docker-build.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: Build and Push Docker Image - -on: - push: - branches: [ '**' ] - -jobs: - build-and-push: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Login to DockerHub - uses: docker/login-action@v3 - with: - username: audiusci - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Extract metadata for Docker - id: meta - uses: docker/metadata-action@v5 - with: - images: audius/api - tags: | - type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }} - type=sha - - - name: Build and push - uses: docker/build-push-action@v5 - with: - context: . - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - cache-from: type=registry,ref=audius/api:buildcache - cache-to: type=registry,ref=audius/api:buildcache,mode=max \ No newline at end of file From c6a381bf1d2497c3e202d4c7df5b976edce28a41 Mon Sep 17 00:00:00 2001 From: Raymond Jacobson Date: Wed, 21 May 2025 14:02:45 -0400 Subject: [PATCH 6/6] Fix sha build --- .github/workflows/build.yml | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0bbe94d2..155c0695 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,17 +20,21 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Get full SHA - id: sha - run: echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT + - name: Extract metadata for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: audius/api + tags: | + type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }} + type=sha,prefix= - name: Build and push uses: docker/build-push-action@v5 with: context: . push: true - tags: | - audius/api:latest,enable=${{ github.ref == 'refs/heads/main' }} - audius/api:${{ steps.sha.outputs.sha }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} cache-from: type=registry,ref=audius/api:buildcache cache-to: type=registry,ref=audius/api:buildcache,mode=max \ No newline at end of file