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

Fix python wrapper after upgrading electionguard to 1.2.3 #306

Merged
merged 21 commits into from
Sep 27, 2023
Merged
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
1 change: 0 additions & 1 deletion Dockerfile

This file was deleted.

101 changes: 101 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# This stage builds the python-wrapper package
FROM decidim/ruby-node-python-electionguard:ruby-3.1.1-node-16-python-3.8.11-electionguard-1.2.3 as python-wrapper-builder
LABEL author="[email protected]"

# Add Makefiles
ADD Makefile /code/Makefile
ADD bulletin_board/server.mk /code/bulletin_board/server.mk
ADD bulletin_board/client.mk /code/bulletin_board/client.mk
ADD voting_schemes/dummy/makefile.mk /code/voting_schemes/dummy/makefile.mk
ADD voting_schemes/electionguard/makefile.mk /code/voting_schemes/electionguard/makefile.mk
ADD verifier/makefile.mk /code/verifier/makefile.mk

# Add the source files
ADD voting_schemes/electionguard/python-wrapper /code/voting_schemes/electionguard/python-wrapper

# This step builds the electionguard-python package and the python wrapper
RUN cd /code && make build_electionguard_python_wrapper

# This stage builds the pyodide packages for the previous python packages
FROM decidim/pyodide-electionguard:pyodide-0.16.1-electionguard-1.2.3 as python-to-js-builder
LABEL author="[email protected]"

ENV PYODIDE_PACKAGES "electionguard,bulletin_board-electionguard"

# Create the source folder
RUN mkdir -p /code

# Add the source files
COPY --from=python-wrapper-builder /code/voting_schemes/electionguard /code/voting_schemes/electionguard
ADD voting_schemes/electionguard/python-to-js /code/voting_schemes/electionguard/python-to-js

# Copy packages definitions to the pyodide source folder
RUN cp -r /code/voting_schemes/electionguard/python-to-js/packages/* /src/pyodide/packages

# Copy the python packages
RUN cp -r /code/voting_schemes/electionguard/electionguard-python/dist /src/pyodide/packages/electionguard/dist
RUN cp -r /code/voting_schemes/electionguard/python-wrapper/dist /src/pyodide/packages/bulletin_board-electionguard/dist

# This step compiles both packages using pyodide
RUN make

# Override some files in the pyodide build
RUN cp -rf /code/voting_schemes/electionguard/python-to-js/override/* /src/pyodide/build/

# This stage builds the bulletin-board application
FROM decidim/ruby-node-python-electionguard:ruby-3.1.1-node-16-python-3.8.11-electionguard-1.2.3
LABEL author="[email protected]"

# Dummy environment variables used to compile assets
ENV SECRET_KEY_BASE 1234
ENV RAILS_ENV production

# Install system dependencies
RUN apt-get update --allow-releaseinfo-change && \
apt-get install -y postgresql postgresql-client postgresql-contrib libpq-dev \
redis-server memcached imagemagick ffmpeg mupdf mupdf-tools libxml2-dev curl && \
rm -rf /var/lib/apt/lists/*

# Add Makefiles
ADD Makefile /code/Makefile
ADD bulletin_board/server.mk /code/bulletin_board/server.mk
ADD bulletin_board/client.mk /code/bulletin_board/client.mk
ADD voting_schemes/dummy/makefile.mk /code/voting_schemes/dummy/makefile.mk
ADD voting_schemes/electionguard/makefile.mk /code/voting_schemes/electionguard/makefile.mk
ADD verifier/makefile.mk /code/verifier/makefile.mk

# Add local dependencies and copy some artifacts from previous stages
ADD bulletin_board/js-client /code/bulletin_board/js-client
ADD bulletin_board/ruby-client /code/bulletin_board/ruby-client
ADD voting_schemes/dummy/js-adapter /code/voting_schemes/dummy/js-adapter
ADD voting_schemes/dummy/ruby-adapter /code/voting_schemes/dummy/ruby-adapter
COPY --from=python-to-js-builder /code/voting_schemes/electionguard /code/voting_schemes/electionguard
ADD voting_schemes/electionguard/js-adapter /code/voting_schemes/electionguard/js-adapter
ADD voting_schemes/electionguard/ruby-adapter /code/voting_schemes/electionguard/ruby-adapter
COPY --from=python-to-js-builder /src/pyodide/build /code/voting_schemes/electionguard/ruby-adapter/public/assets/electionguard

# Add dependencies manifests
ADD bulletin_board/server/package-lock.json /code/bulletin_board/server/package-lock.json
ADD bulletin_board/server/package.json /code/bulletin_board/server/package.json
ADD bulletin_board/server/Gemfile.lock /code/bulletin_board/server/Gemfile.lock
ADD bulletin_board/server/Gemfile /code/bulletin_board/server/Gemfile

# Install all dependencies, build artifacts and remove unnecessary files
RUN cd /code && make install && make build SKIP_PYODIDE=true && \
rm -rf /code/bulletin_board/js-client && \
rm -rf /code/voting_schemes/dummy/js-adapter && \
rm -rf /code/voting_schemes/electionguard/js-adapter && \
rm -rf /root/.cache/Cypress

# Add application source code
ADD bulletin_board/server /code/bulletin_board/server
WORKDIR /code/bulletin_board/server

# Precompile assets
RUN npm install --global yarn
RUN bundle
RUN bundle exec rake assets:precompile

COPY ./docker-entrypoint.sh /
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["bundle", "exec", "rails", "s", "-b", "0.0.0.0"]
4 changes: 2 additions & 2 deletions Dockerfile.release
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ ENV RAILS_ENV production
# Install system dependencies
RUN apt-get update --allow-releaseinfo-change && \
apt-get install -y postgresql postgresql-client postgresql-contrib libpq-dev \
redis-server memcached imagemagick ffmpeg mupdf mupdf-tools libxml2-dev && \
redis-server memcached imagemagick ffmpeg mupdf mupdf-tools libxml2-dev curl && \
rm -rf /var/lib/apt/lists/*

# Add Makefiles
Expand Down Expand Up @@ -96,4 +96,4 @@ RUN npm install --global yarn
RUN bundle
RUN bundle exec rake assets:precompile

CMD ["bundle", "exec", "rails", "s", "-b", "0.0.0.0"]
CMD ["bundle", "exec", "rake", "db:migrate"]
102 changes: 0 additions & 102 deletions Dockerfile.web

This file was deleted.

34 changes: 17 additions & 17 deletions Dockerfile.worker
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
FROM decidim/ruby-node-python-electionguard:ruby-3.1.1-node-16-python-3.8.11-electionguard-1.2.3 as python-wrapper-builder
LABEL author="[email protected]"

# Add Makefile
# Add Makefiles
ADD Makefile /code/Makefile
ADD bulletin_board/server.mk /code/bulletin_board/server.mk
ADD bulletin_board/client.mk /code/bulletin_board/client.mk
ADD voting_schemes/dummy/makefile.mk /code/voting_schemes/dummy/makefile.mk
ADD voting_schemes/electionguard/makefile.mk /code/voting_schemes/electionguard/makefile.mk
ADD verifier/makefile.mk /code/verifier/makefile.mk

# Add the source files
ADD voting_schemes/electionguard/python-wrapper /code/voting_schemes/electionguard/python-wrapper
ADD voting_schemes/electionguard/makefile.mk /code/voting_schemes/electionguard/makefile.mk
ADD voting_schemes/dummy/makefile.mk /code/voting_schemes/dummy/makefile.mk
ADD verifier/makefile.mk /code/verifier/makefile.mk
ADD bulletin_board/client.mk /code/bulletin_board/client.mk
ADD bulletin_board/server.mk /code/bulletin_board/server.mk

# This step builds the electionguard-python package and the python wrapper
RUN cd /code && make build_electionguard_python_wrapper
Expand Down Expand Up @@ -51,13 +51,18 @@ ENV SECRET_KEY_BASE 1234
ENV RAILS_ENV production

# Install system dependencies
RUN apt-get update && \
RUN apt-get update --allow-releaseinfo-change && \
apt-get install -y postgresql postgresql-client postgresql-contrib libpq-dev \
redis-server memcached imagemagick ffmpeg mupdf mupdf-tools libxml2-dev curl && \
rm -rf /var/lib/apt/lists/*

# Add Makefile
# Add Makefiles
ADD Makefile /code/Makefile
ADD bulletin_board/server.mk /code/bulletin_board/server.mk
ADD bulletin_board/client.mk /code/bulletin_board/client.mk
ADD voting_schemes/dummy/makefile.mk /code/voting_schemes/dummy/makefile.mk
ADD voting_schemes/electionguard/makefile.mk /code/voting_schemes/electionguard/makefile.mk
ADD verifier/makefile.mk /code/verifier/makefile.mk

# Add local dependencies and copy some artifacts from previous stages
ADD bulletin_board/js-client /code/bulletin_board/js-client
Expand All @@ -68,11 +73,6 @@ COPY --from=python-to-js-builder /code/voting_schemes/electionguard /code/voting
ADD voting_schemes/electionguard/js-adapter /code/voting_schemes/electionguard/js-adapter
ADD voting_schemes/electionguard/ruby-adapter /code/voting_schemes/electionguard/ruby-adapter
COPY --from=python-to-js-builder /src/pyodide/build /code/voting_schemes/electionguard/ruby-adapter/public/assets/electionguard
ADD verifier/makefile.mk /code/verifier/makefile.mk
ADD voting_schemes/dummy/makefile.mk /code/voting_schemes/dummy/makefile.mk
ADD voting_schemes/electionguard/makefile.mk /code/voting_schemes/electionguard/makefile.mk
ADD bulletin_board/client.mk /code/bulletin_board/client.mk
ADD bulletin_board/server.mk /code/bulletin_board/server.mk

# Add dependencies manifests
ADD bulletin_board/server/package-lock.json /code/bulletin_board/server/package-lock.json
Expand All @@ -81,7 +81,7 @@ ADD bulletin_board/server/Gemfile.lock /code/bulletin_board/server/Gemfile.lock
ADD bulletin_board/server/Gemfile /code/bulletin_board/server/Gemfile

# Install all dependencies, build artifacts and remove unnecessary files
RUN cd /code && make install && make build && \
RUN cd /code && make install && make build SKIP_PYODIDE=true && \
rm -rf /code/bulletin_board/js-client && \
rm -rf /code/voting_schemes/dummy/js-adapter && \
rm -rf /code/voting_schemes/electionguard/js-adapter && \
Expand All @@ -96,6 +96,6 @@ RUN npm install --global yarn
RUN bundle
RUN bundle exec rake assets:precompile

# Run the entrypoint script
COPY ./docker-entrypoint-worker.sh /
ENTRYPOINT ["/docker-entrypoint-worker.sh"]
COPY ./docker-entrypoint.sh /
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["bundle", "exec", "sidekiq", "-C", "config/sidekiq.yml"]
2 changes: 1 addition & 1 deletion bulletin_board/server.mk
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pre_release_server:
kill -9 $$(cat tmp/pids/development.pid) && rm tmp/pids/development.pid

release_server:
docker image build -t ${DOCKER_WEB_IMAGE} -f Dockerfile.web . && \
docker image build -t ${DOCKER_WEB_IMAGE} -f Dockerfile . && \
docker image push ${DOCKER_WEB_IMAGE}

bump_server:
Expand Down
5 changes: 4 additions & 1 deletion bulletin_board/server/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ gem "redis", "~> 4.0"
gem "zlib"

# just in case anyone uses S3
gem "aws-sdk-s3"
gem "aws-sdk-s3", require: false
# uncomment if using these alternatives
# gem "azure-storage-blob", "~> 2.0", require: false
# gem "google-cloud-storage", "~> 1.11", require: false

# Reduces boot times through caching; required in config/boot.rb
gem "bootsnap", ">= 1.4.2", require: false
Expand Down
39 changes: 24 additions & 15 deletions bulletin_board/server/config/storage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,37 @@ local:
root: <%= Rails.root.join("storage") %>

# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
amazon:
s3:
service: S3
access_key_id: <%= ENV['AWS_ACCESS_KEY_ID'] %>
secret_access_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %>
region: <%= ENV['AWS_REGION'] %>
bucket: <%= ENV['AWS_BUCKET_NAME'] %>
<%= "region: #{ENV['AWS_REGION']}" if ENV['AWS_REGION'].present? %>
<%= "endpoint: #{ENV['AWS_ENDPOINT']}" if ENV['AWS_ENDPOINT'].present? %>

# Remember not to checkin your GCS keyfile to a repository
# google:
# service: GCS
# project: your_project
# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %>
# bucket: your_own_bucket
azure:
service: AzureStorage
storage_account_name: <%= ENV['AZURE_STORAGE_ACCOUNT_NAME'] %>
storage_access_key: <%= ENV['AZURE_STORAGE_ACCESS_KEY'] %>
container: <%= ENV['AZURE_CONTAINER'] %>

# Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key)
# microsoft:
# service: AzureStorage
# storage_account_name: your_account_name
# storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %>
# container: your_container_name
gcs:
service: GCS
project: <%= ENV['GCS_PROJECT'] %>
bucket: <%= ENV['GCS_BUCKET'] %>
credentials:
type: <%= ENV['GCS_TYPE'] %>
project_id: <%= ENV['GCS_PROJECT_ID'] %>
private_key_id: <%= ENV['GCS_PRIVATE_KEY_ID'] %>
private_key: <%= ENV['GCS_PRIVATE_KEY'] %>
client_email: <%= ENV['GCS_CLIENT_EMAIL'] %>
client_id: <%= ENV['GCS_CLIENT_ID'] %>
auth_uri: <%= ENV['GCS_AUTH_URI'] %>
token_uri: <%= ENV['GCS_TOKEN_URI'] %>
auth_provider_x509_cert_url: <%= ENV['GCS_AUTH_PROVIDER_X509_CERT_URL'] %>
client_x509_cert_url: <%= ENV['GCS_CLIENT_X509_CERT_URL'] %>

# mirror:
# service: Mirror
# primary: local
# mirrors: [ amazon, google, microsoft ]
# mirrors: [ amazon, google, microsoft ]
Loading
Loading