From 0f5c7a81a2575f70e88cbab95398a063ee392243 Mon Sep 17 00:00:00 2001 From: Nikolai Rodionov Date: Tue, 20 Jun 2023 10:06:54 +0200 Subject: [PATCH] test buildah in actions --- .dockerignore => .containerignore | 0 .github/workflows/build-container.yaml | 52 +++++++++++++++++++++++++ .github/workflows/container-latest.yaml | 52 ------------------------- Dockerfile => Containerfile | 8 ++-- 4 files changed, 56 insertions(+), 56 deletions(-) rename .dockerignore => .containerignore (100%) create mode 100644 .github/workflows/build-container.yaml delete mode 100644 .github/workflows/container-latest.yaml rename Dockerfile => Containerfile (66%) diff --git a/.dockerignore b/.containerignore similarity index 100% rename from .dockerignore rename to .containerignore diff --git a/.github/workflows/build-container.yaml b/.github/workflows/build-container.yaml new file mode 100644 index 0000000..75a7bcb --- /dev/null +++ b/.github/workflows/build-container.yaml @@ -0,0 +1,52 @@ +--- +name: "Build container" + +on: + push: + branches: + - main + tags: + - "v*.*.*" + + +jobs: + containerization: + runs-on: ubuntu-latest + permissions: + packages: write + strategy: + fail-fast: false + matrix: + include: + - arch: amd64 + - arch: arm64 + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Install buildah + run: sudo apt update && sudo apt install -y podman buildah qemu-user-static + + - name: Set version tag (only if triggered by pushing a tag) + if: startsWith(github.ref, 'refs/tags/v') + run: echo "TAG=${GITHUB_REF##*/}" >> $GITHUB_ENV + + - name: Set latest tag (only if triggered by pushing to the main branch) + if: github.ref == 'main' + run: echo "TAG=latest" >> $GITHUB_ENV + + - name: Set action link variable + run: echo "LINK=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> $GITHUB_ENV + + - name: Login in gchr registry + run: buildah login --username ${{ github.repository_owner }} --password ${{ secrets.GITHUB_TOKEN }} ghcr.io + + - name: Build an image + run: | + buildah bud -t ghcr.io/${{ github.repository }}:${{ github.sha }}-${{ matrix.arch }} \ + --label action_id=${{ github.action }} \ + --label action_link=${{ env.LINK }} \ + --label actor=${{ github.actor }} \ + --label sha=${{ github.sha }} \ + --label ref=${{ github.ref }} \ + . \ No newline at end of file diff --git a/.github/workflows/container-latest.yaml b/.github/workflows/container-latest.yaml deleted file mode 100644 index 7aa1d31..0000000 --- a/.github/workflows/container-latest.yaml +++ /dev/null @@ -1,52 +0,0 @@ ---- -name: "Latest container" - -on: - push: - branches: - - main - -jobs: - containerization: - runs-on: ubuntu-latest - permissions: - packages: write - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Set action link variable - run: echo "LINK=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> $GITHUB_ENV - - - name: Set up QEMU - uses: docker/setup-qemu-action@master - with: - platforms: all - - - name: Set up Docker Buildx - id: buildx - uses: docker/setup-buildx-action@master - - - name: Login to GitHub Container Registry - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Build - uses: docker/build-push-action@v3 - with: - builder: ${{ steps.buildx.outputs.name }} - context: . - file: ./Dockerfile - platforms: linux/amd64,linux/arm64 - push: true - tags: | - ghcr.io/${{ github.repository }}:latest - labels: | - action_id=${{ github.action }} - action_link=${{ env.LINK }} - actor=${{ github.actor }} - sha=${{ github.sha }} - ref=${{ github.ref }} diff --git a/Dockerfile b/Containerfile similarity index 66% rename from Dockerfile rename to Containerfile index 7042732..7c609b0 100644 --- a/Dockerfile +++ b/Containerfile @@ -1,4 +1,4 @@ -FROM rust:1.70.0-slim-bookworm as builder +FROM registry.hub.docker.com/library/rust:1.70.0-slim-bookworm as builder WORKDIR /src RUN apt-get update &&\ apt-get install -y libssl-dev gcc musl pkg-config @@ -9,9 +9,9 @@ RUN cargo build --release --jobs 2 -Z sparse-registry FROM debian:stable COPY --from=builder /src/target/release/dudo /bin/dudo -RUN apt-get update &&\ - apt-get install openssl ca-certificates &&\ - apt-get clean +RUN apt-get update -y &&\ + apt-get install openssl ca-certificates -y &&\ + apt-get clean -y RUN chmod +x /bin/dudo WORKDIR /workdir ENTRYPOINT ["/bin/dudo"]