diff --git a/.github/workflows/build-oci.yaml b/.github/workflows/build-oci.yaml index bef883e..95e25c0 100644 --- a/.github/workflows/build-oci.yaml +++ b/.github/workflows/build-oci.yaml @@ -1,37 +1,43 @@ -name: Build OCI image +name: Build and push OCI image on: - release: - types: - - published + push: + tags: + - "**" env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} + VERSION: ${{ github.ref_name }} jobs: build: runs-on: ubuntu-latest + permissions: + contents: read + packages: write steps: - name: Checkout repository uses: actions/checkout@v4 - - name: Log in to the Container registry - uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 - with: - registry: ${{ env.REGISTRY }} - 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 - - name: Build and push - uses: docker/build-push-action@v6 - with: - context: . - file: ./oci/katenary/Containerfile - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - build-args: | - VERSION=${{github.ref_name}} + + - name: Install Buildah + run: |- + if ! comamnd -v buildah 2>/dev/null; then + echo "Install Buildah" + apt-get update + apt-get install -y buildah + else + echo "Buildah already installed" + fi + + - name: Build and tag + run: |- + buildah build --build-arg VERSION=$VERSION -t katenary -f ./oci/katenary/Containerfile . + buildah tag katenary $REGISTRY/${IMAGE_NAME,,}:$VERSION + buildah tag katenary $REGISTRY/${IMAGE_NAME,,}:latest + + - name: Push image + run: |- + buildah login $REGISTRY -u ${{ github.actor }} -p ${{ secret.GITHUB_TOKEN }} + buildah push $REGISTRY/${IMAGE_NAME,,}:$VERSION + buildah push $REGISTRY/${IMAGE_NAME,,}:latest diff --git a/oci/katenary/Containerfile b/oci/katenary/Containerfile index 1ad4387..a5adba5 100644 --- a/oci/katenary/Containerfile +++ b/oci/katenary/Containerfile @@ -1,15 +1,17 @@ ARG GOVERSION=1.24 FROM docker.io/golang:${GOVERSION} AS builder +WORKDIR /go/src/github.com/katenary/katenary +COPY . . ARG VERSION=master RUN set -xe; \ - CGO_ENABLED=0 go install -v github.com/katenary/katenary/cmd/katenary@$VERSION; + CGO_ENABLED=0 go build -ldflags="-X 'github.com/katenary/katenary/internal/generator.Version=$VERSION'" -trimpath -o katenary ./cmd/katenary FROM scratch LABEL org.opencontainers.image.source=https://github.com/katenary/katenary LABEL org.opencontainers.image.description="Katenary converts compose files to Helm Chart" LABEL org.opencontainers.image.licenses=MIT -COPY --from=builder /go/bin/katenary /usr/local/bin/katenary +COPY --from=builder /go/src/github.com/katenary/katenary/katenary /katenary VOLUME /project WORKDIR /project -ENTRYPOINT ["/usr/local/bin/katenary"] +ENTRYPOINT ["/katenary"]