forked from openfoodfoundation/openfoodnetwork
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request openfoodfoundation#12905 from macanudo527/docker/u…
…se_alpine_image Add Alpine Image for Docker
- Loading branch information
Showing
8 changed files
with
98 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 \ | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,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. | ||
|
@@ -32,48 +33,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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters