Skip to content

Commit

Permalink
Adding a new dockerfile using a cross-platform docker
Browse files Browse the repository at this point in the history
  • Loading branch information
Dracks committed Dec 14, 2024
1 parent 2aa3564 commit d665021
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 23 deletions.
26 changes: 3 additions & 23 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]
pull_request:
branches: [ main, develop ]
branches: [ main, mr-scrooge-3.0.0 ]

env:
# Use docker.io for Docker Hub if empty
Expand Down Expand Up @@ -45,14 +45,7 @@ jobs:
- uses: actions/setup-node@v2
with:
node-version: 16

- name: Install node dependencies
working-directory: ./view
run: npm install

- name: build view
working-directory: ./view
run: npm run build


# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
Expand Down Expand Up @@ -95,23 +88,10 @@ jobs:
uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a
with:
context: .
file: ./docker/config/sqlite/Dockerfile
file: ./docker/Dockerfile
platforms: ${{ env.PLATFORMS }}
push: ${{ github.event_name != 'pull_request' }}
tags: "${{ steps.meta.outputs.tags }}"
build-args: |
TAG_NAME=${{ github.ref_name }}
labels: ${{ steps.meta.outputs.labels }}

- name: Build and push Docker postgres image
id: build-and-push-postgres
uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a
with:
context: .
file: ./docker/config/postgres/Dockerfile
platforms: ${{ env.PLATFORMS}}
push: ${{ github.event_name != 'pull_request' }}
tags: "${{ steps.meta-postgres.outputs.tags }},docker.io/dracks/mrscrooge:latest-postgres"
#tags: "${{ steps.meta-postgres.outputs.tags }}"
labels: ${{ steps.meta-postgres.outputs.labels }}

Empty file added Public/.gitkeep
Empty file.
Empty file added Resources/.gitkeep
Empty file.
39 changes: 39 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
FROM --platform=$BUILDPLATFORM node:20-slim as client-build
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable

COPY . /home/app
WORKDIR /home/app
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
RUN pnpm run -r build

FROM --platform=$BUILDPLATFORM swift:6.0.3-noble as server-build
# Cross compilation based on https://swiftinit.org/articles/cross-compiling-x86_64-linux-to-aarch64-linux
RUN apt update && apt -y install gcc-aarch64-linux-gnu g++-multilib
RUN mkdir /home/swift-cross-compile /home/vapor
WORKDIR /home/swift-cross-compile
COPY docker/swift-cross-platform/* /home/swift-cross-compile/

RUN ./download.sh $TARGETPLATFORM && mkdir $TARGETPLATFORM && tar -xzvf swift-$TARGETPLATFORM.tar.gz -C $TARGETPLATFORM

WORKDIR /home/vapor

COPY src /home/vapor/src
COPY Package.swift Package.resolved /home/vapor/
COPY Resources /home/app/Resources
COPY --from=client-build Resources/Views/react.leaf /home/app/Resources/Views/react.leaf

RUN swift build --destination /home/swift-cross-compile/$TARGETPLATFORM.json -c release --static-swift-stdlib

FROM ubuntu:noble
RUN mkdir /home/app
WORKDIR /home/app

COPY --from=server-build /home/vapor/.build/release/MrScroogeServer /home/app/server
COPY Public /home/app/Public
COPY --from=client-build /home/app/Public/react /home/app/Public/react

EXPOSE 8080
ENTRYPOINT [ "./MrScroogeServer" ]
CMD ["serve", "--env", "production", "--hostname", "0.0.0.0", "--port", "8080"]
17 changes: 17 additions & 0 deletions docker/swift-cross-platform/aarch64.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"version": 1,
"target": "aarch64-unknown-linux-gnu",
"toolchain-bin-dir": "/home/ubuntu/usr/bin",
"sdk": "/usr/aarch64-linux-gnu",
"extra-cc-flags": [
"-fPIC"
],
"extra-cpp-flags": [
"-lstdc++",
"-I", "/usr/aarch64-linux-gnu/include/c++/12",
"-I", "/usr/aarch64-linux-gnu/include/c++/12/aarch64-linux-gnu/"
],
"extra-swiftc-flags": [
"-resource-dir", "/home/swift-cross-compile/aarch64/usr/lib/swift"
]
}
9 changes: 9 additions & 0 deletions docker/swift-cross-platform/download.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh
# Download files, from the tarball of the swift page
# They are a copy paste from https://www.swift.org/install/linux/ubuntu/24_04/#latest
echo "Selecting platform for $1"
if [ $1 == "x64_64" ]; then
wget "https://download.swift.org/swift-6.0.3-release/ubuntu2404/swift-6.0.3-RELEASE/swift-6.0.3-RELEASE-ubuntu24.04.tar.gz" -O swift-x86_64.tar.gz
else
wget "https://download.swift.org/swift-6.0.3-release/ubuntu2404-aarch64/swift-6.0.3-RELEASE/swift-6.0.3-RELEASE-ubuntu24.04-aarch64.tar.gz" -O swift-aarch64.tar.gz
fi
17 changes: 17 additions & 0 deletions docker/swift-cross-platform/x86_64.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"version": 1,
"target": "amd64-unknown-linux-gnu",
"toolchain-bin-dir": "/home/ubuntu/usr/bin",
"sdk": "/usr/amd64-linux-gnu",
"extra-cc-flags": [
"-fPIC"
],
"extra-cpp-flags": [
"-lstdc++",
"-I", "/usr/amd64-linux-gnu/include/c++/12",
"-I", "/usr/amd64-linux-gnu/include/c++/12/amd64-linux-gnu/"
],
"extra-swiftc-flags": [
"-resource-dir", "/home/swift-cross-compile/amd64/usr/lib/swift"
]
}

0 comments on commit d665021

Please sign in to comment.