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

Use Alpine Image for Docker #12905

Open
wants to merge 18 commits 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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ RUN ./script/install-bundler
RUN yarn install

# Run bundler install in parallel with the amount of available CPUs
RUN bundle install --jobs="$(nproc)"
RUN bundle install --jobs="$(nproc)"
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ gem "active_model_serializers", "0.8.4"
gem 'activerecord-session_store'
gem 'acts-as-taggable-on'
gem 'angularjs-file-upload-rails', '~> 2.4.1'
gem 'bigdecimal', '3.0.2'
gem 'bigdecimal', '3.1.8'
gem 'bootsnap', require: false
gem 'geocoder'
gem 'gmaps4rails'
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ GEM
base64 (0.2.0)
bcp47_spec (0.2.1)
bcrypt (3.1.20)
bigdecimal (3.0.2)
bigdecimal (3.1.8)
bindata (2.5.0)
bindex (0.8.1)
bootsnap (1.18.3)
Expand Down Expand Up @@ -865,7 +865,7 @@ DEPENDENCIES
angularjs-rails (= 1.8.0)
arel-helpers (~> 2.12)
aws-sdk-s3
bigdecimal (= 3.0.2)
bigdecimal (= 3.1.8)
bootsnap
bugsnag
bullet
Expand Down
32 changes: 32 additions & 0 deletions alpine.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM ruby:3.1.4-alpine3.19 AS base
ENV LANG=C.UTF-8 \
LC_ALL=C.UTF-8 \
TZ=Europe/London \
macanudo527 marked this conversation as resolved.
Show resolved Hide resolved
RAILS_ROOT=/usr/src/app
RUN apk --no-cache upgrade && \
apk add --no-cache tzdata postgresql-client imagemagick imagemagick-jpeg && \
apk add --no-cache --virtual wkhtmltopdf

WORKDIR $RAILS_ROOT

# Development dependencies
FROM base AS development-base
RUN apk add --no-cache --virtual .build-deps \
build-base postgresql-dev git nodejs yarn && \
apk add --no-cache --virtual .dev-utils \
bash curl less vim chromium-chromedriver zlib-dev openssl-dev \
readline-dev yaml-dev sqlite-dev libxml2-dev libxslt-dev libffi-dev vips-dev && \
curl -o /usr/local/bin/wait-for-it https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh && \
chmod +x /usr/local/bin/wait-for-it

# Install yarn dependencies separately for caching
FROM development-base AS yarn-dependencies
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile

# Install Ruby gems
FROM development-base
COPY . $RAILS_ROOT
COPY Gemfile Gemfile.lock ./
RUN bundle install --jobs "$(nproc)"
COPY --from=yarn-dependencies $RAILS_ROOT/node_modules ./node_modules
2 changes: 1 addition & 1 deletion app/services/variant_units/option_value_namer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def option_value_value_unit
def option_value_value_unit_scaled
unit_scale, unit_name = scale_for_unit_value

value = (@nameable.unit_value / unit_scale).to_d.truncate(2)
value = (@nameable.unit_value / unit_scale).to_d.round(2)

[value, unit_name]
end
Expand Down
5 changes: 3 additions & 2 deletions docker-compose.yml → compose.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3'

services:
db:
image: postgres:10.19
Expand All @@ -24,6 +22,8 @@ services:
- .:/usr/src/app
- gems:/bundles
- ./config/database.yml:/usr/src/app/config/database.yml
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
depends_on:
- db
- redis
Expand All @@ -32,6 +32,7 @@ services:
OFN_DB_HOST: db
OFN_REDIS_URL: redis://redis/
OFN_REDIS_JOBS_URL: redis://redis
OFN_REDIS_TEST_URL: redis://redis/3
WEBPACKER_DEV_SERVER_HOST: webpack
command: >
bash -c "wait-for-it -t 30 db:5432 &&
Expand Down
79 changes: 41 additions & 38 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ Note: There is no need to install Docker Desktop on Linux.
* You may have to deselect the option to use Docker Compose V2 in Docker settings to make our scripts work.

## Getting Started
### Linux

1. **Clone the Repository**:
* Open a terminal with a shell.
* Clone the repository. If you're planning on contributing code to the project (which we [LOVE](CONTRIBUTING.md)), begin by forking this repo with the Fork button in the top-right corner of this screen.
* Use git clone to copy your fork onto your local machine.
Expand All @@ -35,48 +36,50 @@ $ git clone https://github.com/YOUR_GITHUB_USERNAME_HERE/openfoodnetwork
```sh
$ git clone [email protected]:openfoodfoundation/openfoodnetwork.git
```
* Go at the root of the app:

2. **Navigate to the App Directory**:
```sh
$ cd openfoodnetwork
```
* Download the Docker images, build the Docker containers, seed the database with sample data, AND log the screen output from these tasks:
```sh
$ docker/build
```
* Run the Rails server and its required Docker containers:
```sh
$ docker/server
```
* The default admin user is '[email protected]' with the password 'ofn123'.
* View the app in the browser at `http://localhost:3000`.
* You will then get the trace of the containers in the terminal. You can stop the containers using Ctrl-C in the terminal.
* You can find some useful tips and commands [here](https://github.com/openfoodfoundation/openfoodnetwork/wiki/Docker:-useful-tips-and-commands).

### Windows
* Prerequisite : don't forget to activate the execution of powershell scripts following the instruction on [this page chosing "Using RemoteSigned Execution Policy"](https://shellgeek.com/powershell-fix-running-scripts-is-disabled-on-this-system/)
* Open a terminal with a shell command.
* Clone the repository. If you're planning on contributing code to the project (which we [LOVE](CONTRIBUTING.md)), begin by forking this repo with the Fork button in the top-right corner of this screen.
* Use git clone to copy your fork onto your local machine.
```command
$ git clone https://github.com/YOUR_GITHUB_USERNAME_HERE/openfoodnetwork
```
* Otherwise, if you just want to get things running, clone from the OFN main repo:
```command
$ git clone [email protected]:openfoodfoundation/openfoodnetwork.git
```
* Go at the root of the app:
```command
$ cd openfoodnetwork
```
* Download the Docker images, build the Docker containers, seed the database with sample data, AND log the screen output from these tasks:
```command
$ docker/build.ps1
```
3. **Choose and Build Docker Image**:
* You have two choices of images you can build. The default Ubuntu image is most similar to the production servers but is larger in size and will take longer to build. Alternatively, you can use the Alpine image which is smaller, faster to setup, and should be compatible with the Ubuntu. However, it will need to be updated when ruby is updated. To download the Docker images, build the Docker containers, seed the database with sample data, AND log the screen output from these tasks:
- **Ubuntu Image** (larger, production-like):
- **Linux**:
```sh
$ docker/build
```
- **Windows**:
```command
$ docker/build.ps1
```
- **Alpine Image** (smaller, faster):
- **Linux**:
```sh
$ docker/build alpine.Dockerfile
```
- **Windows**:
```command
$ docker/build.ps1 alpine.Dockerfile
```

4. **Run the Rails Server**:
* Run the Rails server and its required Docker containers:
```command
$ docker/server.ps1
```
You may need to wait several minutes before getting the server up and running properly.
- **Linux**:
```sh
$ docker/server
```
- **Windows**:
```command
$ docker/server.ps1
```
* To run tests or access the server directly, you can use bash:
```sh
$ docker compose exec web bash
```

> **Note**: Windows users may need to enable PowerShell script execution by setting the RemoteSigned policy. See instructions [here](https://shellgeek.com/powershell-fix-running-scripts-is-disabled-on-this-system/).

* The default admin user is '[email protected]' with the password 'ofn123'.
* View the app in the browser at `http://localhost:3000`.
* You will then get the trace of the containers in the terminal. You can stop the containers using Ctrl-C in the terminal.
Expand Down
2 changes: 1 addition & 1 deletion docker/build
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ set -e
# This script builds the Docker container, seeds the app with sample data, and logs the screen output.

DATE=`date +%Y%m%d-%H%M%S-%3N`
docker/build-log 2>&1 | tee log/build-$DATE.log
docker/build-log $1 2>&1 | tee log/build-$DATE.log
docker/seed 2>&1 | tee log/seed-$DATE.log
6 changes: 5 additions & 1 deletion docker/build-log
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ wait
echo '###########################'
echo 'BEGIN: docker compose build'
echo '###########################'
docker compose build # Set up the Docker containers
if [ -n "$1" ]; then
docker build -f $1 . # Set up the Docker containers
else
docker compose build # Set up the Docker containers
fi
echo '##############################'
echo 'FINISHED: docker compose build'
echo '##############################'
9 changes: 8 additions & 1 deletion docker/build-log.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
Write-Host "Docker cleaning: remove old containers" -ForegroundColor Blue
docker compose down -v --remove-orphans
Write-Host "Docker build: set up the docker containers" -ForegroundColor Blue
docker compose build

# Check if an argument is provided
if ($args.Count -gt 0) {
# Run the build command with the argument and log output
docker build -f $1 .
} else {
docker compose build
}
Write-Host "Docker build finished"
8 changes: 7 additions & 1 deletion docker/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,11 @@

$DateTime=Get-Date -Format "yyyyMMdd-HHmmss"

docker/build-log.ps1 > log/build-$DateTime.log 2>&1
# Check if an argument is provided
if ($args.Count -gt 0) {
# Run the build command with the argument and log output
docker/build-log.ps1 $args[0] > log/build-$DateTime.log 2>&1
} else {
docker/build-log.ps1 > log/build-$DateTime.log 2>&1
}
docker/seed.ps1 > log/seed-$DateTime.log 2>&1
2 changes: 1 addition & 1 deletion spec/lib/reports/sales_tax_totals_by_order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
total = report.total_excl_tax(query_row)

# discounted order total - discounted order tax
expect(total).to eq((113.3 - 10) - (3.3 - 0.29))
expect(total).to eq((BigDecimal('113.3') - 10) - (BigDecimal('3.3') - BigDecimal('0.29')))
end
end
end
Expand Down
Loading