Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Docker pipeline #295

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/push-docker-image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Push Docker image

on:
push:
tags: [ 'v*.*.*' ]

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
main:
name: Build and push Docker image
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]

- name: Set up Docker Buildx
uses: docker/[email protected]

- name: Log into registry ${{ env.REGISTRY }}
uses: docker/[email protected]
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract Docker metadata
id: meta
uses: docker/[email protected]
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
id: build-and-push
uses: docker/[email protected]
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
45 changes: 45 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Shared layer with dependencies
FROM alpine:3.20.1 AS shared

## Install shared dependencies
RUN apk update
RUN apk add --no-cache openssl
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is good practice to combine the RUN commands into on single command in order to not create unnecessary layers in the final images. As the shared image is also being used by the final image, it would make sense to combine them:

RUN apk add --no-cache openssl make lua5.1 pcre2

Also, apk update is not needed here: when called with the --no-cache option, apk add does not make use of any locally cached information (as provided by apk update) but instead fetches all required data from the repo. 😊

RUN apk add --no-cache make
RUN apk add --no-cache lua5.1
RUN apk add --no-cache pcre2



# Build layer with dev-dependencies
FROM shared AS build

## Install build dependencies
RUN apk add --no-cache openssl-dev
RUN apk add --no-cache alpine-sdk
RUN apk add --no-cache lua5.1-dev
RUN apk add --no-cache pcre2-dev


## Build imapfilter
WORKDIR /dist
COPY ./ /dist/
RUN make all



# Final layer with installed imapfilter
FROM shared AS final

## Install imapfilter
COPY --from=build /dist /dist
WORKDIR /dist
RUN make install


# Clean-up dist
RUN rm -rf /dist
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, this should be combined into one RUN command instead to reduce overhead:

RUN make install && rm -rf /dist



WORKDIR /

ENTRYPOINT [ "imapfilter" ]