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

chore: fe deployment #85

Closed
wants to merge 3 commits into from
Closed
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
16 changes: 11 additions & 5 deletions Dockerfile.web
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@ FROM node:16

WORKDIR /app/
COPY react-web /app
COPY ./docker-files/.env.local .
RUN npm install
#COPY ./docker-files/.env.local .
RUN npm install --global serve
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

The serve package is being installed globally. This package is typically used to serve static files. If the application relies on other packages that were previously installed with npm install, those packages may not be available anymore. Please ensure that all necessary dependencies are still being installed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not bad 😄


#"homepage": "https://input-output-hk.github.io/dapps-certification/"
RUN sed -i 's/https:\/\/input-output-hk.github.io\/dapps-certification/http:\/\/localhost:3000/g' package.json
RUN sed -i 's/http:\/\/excuse.ro:9672/https:\/\/dapps-certification.scdev.aws.iohkdev.io/g' package.json
#"proxy": "https://testing.dapps.iog.io/"
RUN sed -i 's/https:\/\/testing.dapps.iog.io/http:\/\/localhost:3000/g' package.json
RUN sed -i 's/http:\/\/localhost:3000/http:\/\/localhost:80/g' package.json

RUN npm install
RUN rm -rf ./.env
#RUN rm ./.env.production

RUN npm run build
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

The npm run build command is being executed. This command typically creates a production-ready version of the application. If there are any build scripts that need to be run before this command, they may not be executed anymore. Please ensure that all necessary build steps are still being performed.


COPY ./docker-files/start_web.sh .
RUN chmod +x ./start_web.sh

ENTRYPOINT [ "./start_web.sh" ]
#ENTRYPOINT [ "/bin/sh","-c","./start_web.sh"]
CMD [ "npm","start" ]
#CMD [ "npm","start" ]
Copy link
Contributor

@coderabbitai coderabbitai bot Aug 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

The CMD command has been commented out. This command specifies the default command that should be run when the container starts. If the ENTRYPOINT command does not start the application, it may not run when the container starts. Please ensure that the application is started correctly when the container runs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

@RSoulatIOHK Sure, I'd be happy to explain further.

In a Dockerfile, the CMD instruction provides defaults for an executing container. These can include an executable, or they can omit the executable, in which case you must specify an ENTRYPOINT instruction. The CMD values can be overridden when starting a container.

The ENTRYPOINT instruction allows you to configure a container that will run as an executable. It has two forms:

  1. The exec form, which is the preferred form: ENTRYPOINT ["executable", "param1", "param2"]
  2. The shell form, ENTRYPOINT command param1 param2

In your Dockerfile, you have commented out the CMD instruction and are using the ENTRYPOINT instruction to start the application. This means that when the Docker container starts, it will execute the start_web.sh script.

However, if the start_web.sh script does not start the application (for example, if it only prepares the environment), then the application will not run when the Docker container starts. This is because there is no CMD instruction to start the application.

To ensure that your application runs when the Docker container starts, you should either:

  • Make sure that the start_web.sh script starts the application.
  • Uncomment the CMD instruction so that it starts the application after the ENTRYPOINT instruction has completed.

I hope this clarifies things. Let me know if you have any other questions!

Copy link
Collaborator Author

@bogdan-manole bogdan-manole Aug 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CodeRabbit server build command from the last line of the entrypoint file starts the application from the build folder

2 changes: 1 addition & 1 deletion docker-files/run.sh → docker-files/run-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
WALLET_CERTIFICATION_PRICE=1000000 \
JWT_SECRET2=secret \
PORT=80 \
nix run .#runDockerImage
nix run .#server.runDockerImage
2 changes: 2 additions & 0 deletions docker-files/run-web.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
REACT_APP_BASE_URL=http://lix:80 \
nix run .#web.runDockerImage
File renamed without changes.
3 changes: 1 addition & 2 deletions docker-files/start_web.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/bin/bash
#REACT_APP_BASE_URL="http://localhost:9671"
echo $REACT_APP_BASE_URL
npm start
serve -s build


5 changes: 3 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@

flake = project.flake {};

dockerApps = import ./docker-files/docker.nix { pkgs = pkgs; flake = flake; };
serverApps = import ./docker-files/server.nix { pkgs = pkgs; flake = flake; };
webApps = import ./web.nix { pkgs = pkgs; flake = flake; };

in flake // {
packages = flake.packages // {
inherit (project.plan-nix.passthru) generateMaterialized;
};
defaultPackage = flake.packages."plutus-certification:exe:plutus-certification";
apps = flake.apps // dockerApps // {
apps = flake.apps // {server = serverApps; web = webApps;} // {
updateAllMaterialized = {
type = "app";
program = (pkgs.writeShellScript "updateAllMaterialized" ''
Expand Down
4 changes: 2 additions & 2 deletions react-web/.env.production
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
REACT_APP_BASE_URL="https://testing.dapps.iog.io/"
REACT_APP_WALLET_NETWORK="1"
REACT_APP_BASE_URL="https:\\dapps-certification.scdev.aws.iohkdev.io"
REACT_APP_WALLET_NETWORK="1"
63 changes: 63 additions & 0 deletions web.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{ pkgs,flake, ... }: let
pkgsLinux = pkgs // { system = "x86_64-linux"; };
imgAttributes = {
name = "plutus-certification-web";
tag = "5";
};
loadDockerImage = {
type= "app";
program = (pkgs.writeShellScript "loadDockerImage" ''
set -eEuo pipefail
# build ./Dockerfile.web image and load it into docker
${pkgs.docker}/bin/docker build -t ${imgAttributes.name}:${imgAttributes.tag} -f ./Dockerfile.web .
#${pkgs.docker}/bin/docker save ${imgAttributes.name}:${imgAttributes.tag} | ${pkgs.docker}/bin/docker load
#and now load the image into docker
#${pkgs.docker}/bin/docker image ls
'').outPath;
Comment on lines +12 to +16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description CodeRabbit

The command to save and load the Docker image is commented out. If this is intentional, consider removing these lines to avoid confusion.

-           #${pkgs.docker}/bin/docker save ${imgAttributes.name}:${imgAttributes.tag} | ${pkgs.docker}/bin/docker load
-           #and now load the image into docker
-           #${pkgs.docker}/bin/docker image ls

};
in {
loadDockerImage = loadDockerImage;
runDockerImage =
let addEnvVar = varName: ''
if [ -n "${"$"}${varName}" ]; then
docker_args="$docker_args -e ${varName}=${"$"}${varName}"
fi
'';
in {
type = "app";
program = (pkgs.writeShellScript "runDockerImage" ''
set -eEo pipefail
export PATH="${pkgs.lib.makeBinPath [ pkgs.docker pkgs.coreutils]}"
echo "Executing ${loadDockerImage.program}..." >&2
${loadDockerImage.program}
docker_args="-t --name ${imgAttributes.name} -p 80:3000"

${addEnvVar "REACT_APP_BASE_URL"}

script="docker run --rm $docker_args ${imgAttributes.name}:${imgAttributes.tag}"
echo $script >&2
eval "$script"
'').outPath;
};
pushDockerImage = {
type = "app";
#usage: nix run .\#apps.x86_64-linux.pushDockerImage -- <docker registry>
#E.g. nix run .\#apps.x86_64-linux.pushDockerImage -- ghcr.io/demoiog
program = (pkgs.writeShellScript "pushDockerImage" ''
set -eEuo pipefail
export PATH="${pkgs.lib.makeBinPath [ pkgs.docker pkgs.coreutils]}"
${loadDockerImage.program}
echo "Pushing docker image ${imgAttributes:name}:${imgAttributes.tag}" >&2
imageName="${imgAttributes.name}:${imgAttributes.tag}"

script="docker image tag $imageName $1/$imageName"
echo $script >&2
eval "$script"

script="docker push $1/$imageName"
echo $script >&2
eval "$script"

'').outPath;
};
}
Loading