Skip to content

Commit

Permalink
Add Dockerfile (#1211)
Browse files Browse the repository at this point in the history
* Add Dockerfile

To simplify building on Linux:

```console
docker build -t sourcery-image .
docker run sourcery-image sourcery --help
```

I've kept the resulting Docker image small(-ish) at the expense of
probably removing some useful functionality. I haven't tested this
thoroughly but I'll leave it to other contributors can expand this as
needed.

* Simplfy build flags

Since the runtime image is also Swift.

* Add CI job to build and publish docker images to GitHub Packages

Will run on commits to the `master` branch and tags.
  • Loading branch information
jpsim authored Oct 17, 2023
1 parent bf0df0f commit f92cd86
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 0 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Docker

on:
push:
branches:
- master
tags:
- '*'

jobs:
build:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v3

- name: Extract DOCKER_TAG using tag name
if: startsWith(github.ref, 'refs/tags/')
run: |
echo "DOCKER_TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
- name: Use default DOCKER_TAG
if: startsWith(github.ref, 'refs/tags/') != true
run: |
echo "DOCKER_TAG=latest" >> $GITHUB_ENV
- name: Set lowercase repository name
run: |
echo "REPOSITORY_LC=${REPOSITORY,,}" >>${GITHUB_ENV}
env:
REPOSITORY: '${{ github.repository }}'

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to GitHub registry
uses: docker/login-action@v1
with:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io

- uses: docker/build-push-action@v2
with:
push: true
tags: ghcr.io/${{ env.REPOSITORY_LC }}:${{ env.DOCKER_TAG }}
45 changes: 45 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
ARG BUILDER_IMAGE=swift:5.9-jammy
ARG RUNTIME_IMAGE=swift:5.9-jammy-slim

# Builder image
FROM ${BUILDER_IMAGE} AS builder
RUN apt-get update && apt-get install -y \
build-essential \
libffi-dev \
libncurses5-dev \
libsqlite3-dev \
&& rm -r /var/lib/apt/lists/*
WORKDIR /workdir/
COPY Sourcery Sourcery/
COPY SourceryExecutable SourceryExecutable/
COPY SourceryFramework SourceryFramework/
COPY SourceryJS SourceryJS/
COPY SourceryRuntime SourceryRuntime/
COPY SourceryStencil SourceryStencil/
COPY SourcerySwift SourcerySwift/
COPY SourceryTests SourceryTests/
COPY SourceryUtils SourceryUtils/
COPY Plugins Plugins/
COPY Templates Templates/
COPY Tests Tests/
COPY Package.* ./

RUN swift package update
ARG SWIFT_FLAGS="-c release"
RUN swift build $SWIFT_FLAGS --product sourcery
RUN mv `swift build $SWIFT_FLAGS --show-bin-path`/sourcery /usr/bin
RUN sourcery --version

# Runtime image
FROM ${RUNTIME_IMAGE}
LABEL org.opencontainers.image.source https://github.com/krzysztofzablocki/Sourcery
RUN apt-get update && apt-get install -y \
libcurl4 \
libsqlite3-0 \
libxml2 \
&& rm -r /var/lib/apt/lists/*
COPY --from=builder /usr/bin/sourcery /usr/bin

RUN sourcery --version

CMD ["sourcery"]
14 changes: 14 additions & 0 deletions LINUX.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ All issues related to Linux will be mentioned in #1198

Simply add package dependency of Sourcery as described in the [README](README.md).

## Using Sourcery with Docker

You can build Docker container with Sourcery installed using this command:

```console
docker build -t sourcery-image .
```

Then you can run this Docker image passing the arguments you'd like:

```console
docker run sourcery-image sourcery --help
```

## Contributing
### Installation of Linux Environment

Expand Down

0 comments on commit f92cd86

Please sign in to comment.