-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Edited the Dockerfile's, added other files, and edited the deploy wor…
…kflow to get docker bulding and releasing to Heroku.
- Loading branch information
1 parent
d14773d
commit 8574bd6
Showing
12 changed files
with
133 additions
and
59 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Your workflow name. | ||
name: Deploy to heroku. | ||
|
||
# Run workflow on every push to dev branch | ||
on: | ||
push: | ||
branches: HW-166-add-tests-to-docker-container | ||
# Your workflows jobs. | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
# Check-out your repository. | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
# Set up Docker Buildx (optional, but recommended for multi-platform builds) | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
|
||
# Log in to Docker Hub (if needed, otherwise skip this step) | ||
- name: Log in to Heroku Container Registry | ||
run: echo "${{ secrets.HEROKU_API_KEY }}" | docker login --username=__token__ --password-stdin registry.heroku.com | ||
|
||
# Build Docker images | ||
- name: Build and Tag Docker Images | ||
run: | | ||
docker build -f ./code/server/Dockerfile.production -t registry.heroku.com/${{ secrets.HEROKU_APP_NAME }}/api-production:1.0.0 ./code | ||
docker build -f ./code/client/Dockerfile.production -t registry.heroku.com/${{ secrets.HEROKU_APP_NAME }}/client-production:1.0.0 ./code | ||
# Push Docker images to Heroku | ||
- name: Push Docker Images to Heroku | ||
run: | | ||
docker push registry.heroku.com/${{ secrets.HEROKU_APP_NAME }}/api-production:1.0.0 | ||
docker push registry.heroku.com/${{ secrets.HEROKU_APP_NAME }}/client-production:1.0.0 | ||
# Release the Docker images | ||
- name: Release Docker Images on Heroku | ||
run: | | ||
heroku container:release web api --app ${{ secrets.HEROKU_APP_NAME }} |
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,2 @@ | ||
web: docker run -p $PORT:$PORT registry.heroku.com/${HEROKU_APP_NAME}/client-production:1.0.0 | ||
api: docker run -p 5000:5000 registry.heroku.com/${HEROKU_APP_NAME}/api-production:1.0.0 |
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,25 +1,43 @@ | ||
# Use an official Node.js image as the base image | ||
FROM node:20.17.0-slim AS builder | ||
FROM node:20.17.0-alpine AS builder | ||
|
||
# Set the working directory inside the container | ||
WORKDIR /app | ||
|
||
# Copy the package.json and package-lock.json files first to leverage Docker caching | ||
COPY package*.json ./ | ||
COPY package.json ./ | ||
COPY package-lock.json ./ | ||
|
||
|
||
# Install dependencies | ||
RUN npm install | ||
RUN npm ci | ||
|
||
# Copy the rest of the application source code | ||
COPY . . | ||
|
||
# Set environment variable for production build | ||
ENV NODE_ENV=production | ||
|
||
# Build the React app | ||
RUN npm run build | ||
|
||
# Use an Nginx image for serving the app | ||
# Use an official Nginx image as a base | ||
FROM nginx:alpine | ||
|
||
# Copy the build output to Nginx's html directory | ||
COPY --from=builder /app/build /usr/share/nginx/html | ||
# Copy the shared Nginx configuration template from the host machine | ||
COPY ../config/nginx.conf.template /etc/nginx/nginx.conf.template | ||
|
||
# Copy your web files to the container | ||
COPY --from=build /app/build /usr/share/nginx/html | ||
|
||
# Expose the port that the application will run on | ||
EXPOSE 80 | ||
CMD ["nginx", "-g", "daemon off;"] | ||
|
||
# Copy the shared entrypoint script from the config folder (relative to the build context) | ||
COPY ../config/entrypoint.sh /entrypoint.sh | ||
|
||
# Make the entrypoint script executable | ||
RUN chmod +x /entrypoint.sh | ||
|
||
# Specify the entrypoint | ||
ENTRYPOINT ["/entrypoint.sh"] |
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,6 @@ | ||
#!/bin/sh | ||
# Substitute environment variables into the Nginx configuration | ||
envsubst '${PORT}' < /etc/nginx/nginx.conf.template > /etc/nginx/nginx.conf | ||
|
||
# Start Nginx | ||
nginx -g 'daemon off;' |
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,24 @@ | ||
# /etc/nginx/nginx.conf | ||
events {} | ||
|
||
http { | ||
include mime.types; | ||
default_type application/octet-stream; | ||
|
||
server { | ||
listen 80; | ||
|
||
location / { | ||
root /usr/share/nginx/html; | ||
index index.html; | ||
try_files $uri /index.html; | ||
} | ||
|
||
# Additional configuration to ensure correct MIME types for static assets | ||
location ~* \.(css|js|woff2?|ttf|eot|svg|png|jpg|jpeg|gif)$ { | ||
root /usr/share/nginx/html; | ||
expires 1d; | ||
add_header Cache-Control "public, must-revalidate, proxy-revalidate"; | ||
} | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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,3 +1,5 @@ | ||
node_modules | ||
dist | ||
*.env | ||
npm-debug.log | ||
Dockerfile* | ||
docker-compose* | ||
.git |
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