diff --git a/.github/workflows/build-publish.yaml b/.github/workflows/build-publish.yaml new file mode 100644 index 0000000..45d3c47 --- /dev/null +++ b/.github/workflows/build-publish.yaml @@ -0,0 +1,54 @@ +name: Build and Publish + +on: + push: + +permissions: + packages: write + contents: write + +jobs: + build-and-push-docker-image: + name: Build Docker image and push + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup Go + uses: actions/setup-go@v4 + with: + go-version: 'stable' + + - uses: go-semantic-release/action@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Setup ko + uses: ko-build/setup-ko@v0.6 + + - name: Login to Github Packages + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build containers + run: | + git fetch --tags + descr=$(git describe --tags) + short=$(git describe --tags --abbrev=0) + export version="${descr#v}" + if [[ $descr == $short ]]; then + minor="${version%.*}" + major="${version%%.*}" + ko build --bare --sbom=none -t edge -t latest -t "$version" -t "$minor" -t "$major" . + else + ko build --bare --sbom=none -t edge . + fi + env: + KO_DOCKER_REPO: ghcr.io/kastelo/go-import-redirector diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 699e9ed..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: Build -on: - pull_request: - push: - branches: - - main - -jobs: - build-server: - runs-on: ubuntu-latest - name: Build - steps: - - - uses: actions/checkout@v2 - - - name: Build binary - uses: addnab/docker-run-action@v3 - with: - registry: docker.io - image: golang:latest - options: -v ${{ github.workspace }}:/src -w /src - run: make - - - name: Log in to the GitHub container registry - uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Build and push - id: docker_build - uses: docker/build-push-action@v3 - with: - context: . - push: true - platforms: linux/amd64,linux/arm64 - tags: ghcr.io/kastelo/go-import-redirector:latest diff --git a/.ko.yaml b/.ko.yaml new file mode 100644 index 0000000..a1affb8 --- /dev/null +++ b/.ko.yaml @@ -0,0 +1,3 @@ +defaultPlatforms: +- linux/arm64 +- linux/amd64 diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index b85033f..0000000 --- a/Dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -FROM gcr.io/distroless/static:nonroot -ARG TARGETARCH -COPY go-import-redirector-$TARGETARCH /bin/go-import-redirector -ENTRYPOINT ["/bin/go-import-redirector"]