klausi / mastodon-twitter-sync

Synchronizes posts from Mastodon to Twitter and back
GNU General Public License v3.0
245 stars 24 forks source link

chore(build): refactor docker image building #44

Closed jdrouet closed 2 years ago

jdrouet commented 2 years ago

This PR reduces the size of the docker image to 27Mo for the alpine image and 129Mo for the debian based image (could use slim tag to make it even smaller).

In a next PR, if you want, I could tackle the multi arch build (amd64, arm64 and armv7).

klausi commented 2 years ago

After fixing the Github actions syntax errors it has now built the image. Unfortunately the binary does not work:

docker run -it --rm -v "$(pwd)":/data klausi/mastodon-twitter-sync

echo $?
139

Return code 139 means segmentation fault as far as I know?

So I think we have to revert this for now until we find a working solution for Alpine Linux. My code comment from the Docker file is still right: "# We get segmentation faults with the Alpine Rust image, so we use the bigger default one.".

Do you know how to run Rust programs in Alpine Linux so that they don't produce segmentation faults?

klausi commented 2 years ago

Reverted all the changes again - let me know if you can create a working Alpine linux image in a new pull request!

klausi commented 2 years ago

Tried your Debian image and that does not work either:

Error connecting to Mastodon: Http(
    reqwest::Error {
        kind: Request,
        url: Url {
            scheme: "https",
            cannot_be_a_base: false,
            username: "",
            password: None,
            host: Some(
                Domain(
                    "mastodon.social",
                ),
            ),
            port: None,
            path: "/api/v1/accounts/verify_credentials",
            query: None,
            fragment: None,
        },
        source: hyper::Error(
            Connect,
            Ssl(
                Error {
                    code: ErrorCode(
                        1,
                    ),
                    cause: Some(
                        Ssl(
                            ErrorStack(
                                [
                                    Error {
                                        code: 337047686,
                                        library: "SSL routines",
                                        function: "tls_process_server_certificate",
                                        reason: "certificate verify failed",
                                        file: "../ssl/statem/statem_clnt.c",
                                        line: 1914,
                                    },
                                ],
                            ),
                        ),
                    ),
                },
                X509VerifyResult {
                    code: 20,
                    error: "unable to get local issuer certificate",
                },
            ),
        ),
    },
)

Looks like some CA certificates are missing?

The docker image size is 57 MB for the Debian image, so if we could get that running that would be huge improvement as well!

klausi commented 2 years ago

Was able to get the reduced Debian image working in #45 , yay! Compressed image size is now 70 MB, which is a reduction by 90%. Impressive, thanks for the inspiration!

klausi commented 2 years ago

Good news: I was able to remove the runtime dependency to OpenSSL (it is still in the dependency tree, but we don't invoke it). Pushed your Alpine Linux Dockerfile now, thanks!

I think we don't need the Debian image, left that out.