From 08396dcade6237d46b4a76967f19c4159df2df8a Mon Sep 17 00:00:00 2001 From: Joe Yates Date: Thu, 2 Nov 2023 16:58:09 +0100 Subject: [PATCH] Create a container image --- .github/workflows/publish-image.yaml | 48 ++++++++++++++++++++++++++++ container/.containerignore | 6 ++++ container/Containerfile | 12 +++++++ 3 files changed, 66 insertions(+) create mode 100644 .github/workflows/publish-image.yaml create mode 100644 container/.containerignore create mode 100644 container/Containerfile diff --git a/.github/workflows/publish-image.yaml b/.github/workflows/publish-image.yaml new file mode 100644 index 00000000..e3b644e5 --- /dev/null +++ b/.github/workflows/publish-image.yaml @@ -0,0 +1,48 @@ +name: Build and publish the production container image to the GitHub Registry + +# Run this workflow every time on every push to the branch `release`. +on: + push: + branches: ['feature/runnable-container'] + +env: + IMAGE_NAME: imap-backup + REGISTRY_USER: ${{ github.actor }} + REGISTRY_PASSWORD: ${{ github.token }} + REGISTRY: ghcr.io/${{ github.repository_owner }} + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. + permissions: + contents: read + packages: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Build Image + # https://github.com/marketplace/actions/buildah-build + id: build-image + uses: redhat-actions/buildah-build@v2 + with: + image: ${{ env.IMAGE_NAME }} + tags: latest ${{ github.sha }} + extra-args: | + --ignorefile ./container/.containerignore + containerfiles: | + ./container/Containerfile + labels: | + ${{ env.IMAGE_NAME }}:latest + + - name: Publish Image + # https://github.com/marketplace/actions/push-to-registry + id: push-to-registry + uses: redhat-actions/push-to-registry@v2 + with: + image: ${{ steps.build-image.outputs.image }} + tags: ${{ steps.build-image.outputs.tags }} + registry: ${{ env.REGISTRY }} + username: ${{ env.REGISTRY_USER }} + password: ${{ env.REGISTRY_PASSWORD }} diff --git a/container/.containerignore b/container/.containerignore new file mode 100644 index 00000000..9244b63e --- /dev/null +++ b/container/.containerignore @@ -0,0 +1,6 @@ +* +!bin/imap-backup +!Gemfile +!imap-backup.gemspec +!lib +!LICENSE diff --git a/container/Containerfile b/container/Containerfile new file mode 100644 index 00000000..c1386661 --- /dev/null +++ b/container/Containerfile @@ -0,0 +1,12 @@ +FROM docker.io/library/ruby:3.2.2-alpine3.18 + +WORKDIR /app + +COPY . . +RUN \ + gem install bundler --version "2.4.21" && \ + BUNDLE_WITHOUT=development bundle install && \ + rm -f /usr/local/bundle/bin/imap-backup +ENV PATH=${PATH}:/app/bin + +CMD ["imap-backup", "backup", "-c", "/config/imap-backup.json"]