-
Notifications
You must be signed in to change notification settings - Fork 1
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 #11 from hppanpaliya/react-inject-env
Optimize Docker setup and build process
- Loading branch information
Showing
18 changed files
with
3,965 additions
and
3,249 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 |
---|---|---|
@@ -1,18 +1,98 @@ | ||
# name: remote ssh command | ||
# on: [push] | ||
# jobs: | ||
|
||
# build: | ||
# name: Build React on remote server | ||
# runs-on: ubuntu-latest | ||
# steps: | ||
# - name: executing remote ssh commands using password | ||
# uses: appleboy/ssh-action@v1.0.0 | ||
# with: | ||
# host: ${{ secrets.HOST }} | ||
# username: ${{ secrets.USERNAME }} | ||
# password: ${{ secrets.PASSWORD }} | ||
# port: ${{ secrets.PORT }} | ||
# script: | | ||
# rm -r /home/harshal/React-TrashMail/mailserver/build | ||
# cd /home/harshal/React-TrashMail/react && yarn && yarn build | ||
name: Build React App and Docker Image | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
env: | ||
DOCKER_REPOSITORY: hppanpaliya/react-trashmail | ||
|
||
jobs: | ||
build-and-push: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
platform: [linux/amd64, linux/arm64] | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '18' | ||
|
||
- name: Install React dependencies | ||
run: yarn install --frozen-lockfile | ||
working-directory: ./react | ||
|
||
- name: Build React app | ||
run: yarn build | ||
working-directory: ./react | ||
|
||
- name: Delete node_modules from React app | ||
run: rm -rf ./node_modules | ||
working-directory: ./react | ||
|
||
- name: Install Mailserver dependencies | ||
run: yarn install --frozen-lockfile | ||
working-directory: ./mailserver | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Log in to Docker Hub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKER_HUB_USERNAME }} | ||
password: ${{ secrets.DOCKER_HUB_TOKEN }} | ||
|
||
- name: Extract platform short name | ||
id: platform | ||
run: | | ||
if [[ "${{ matrix.platform }}" == "linux/amd64" ]]; then | ||
echo "short=amd64" >> $GITHUB_OUTPUT | ||
elif [[ "${{ matrix.platform }}" == "linux/arm64" ]]; then | ||
echo "short=arm64" >> $GITHUB_OUTPUT | ||
fi | ||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: . | ||
file: Dockerfile.prod | ||
platforms: ${{ matrix.platform }} | ||
push: true | ||
tags: | | ||
${{ env.DOCKER_REPOSITORY }}:${{ github.sha }} | ||
${{ env.DOCKER_REPOSITORY }}:${{ github.sha }}-${{ steps.platform.outputs.short }} | ||
merge: | ||
runs-on: ubuntu-latest | ||
needs: build-and-push | ||
|
||
steps: | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Log in to Docker Hub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKER_HUB_USERNAME }} | ||
password: ${{ secrets.DOCKER_HUB_TOKEN }} | ||
|
||
- name: Create and push Docker manifest | ||
run: | | ||
docker buildx imagetools create \ | ||
--tag ${{ env.DOCKER_REPOSITORY }}:latest \ | ||
--tag ${{ env.DOCKER_REPOSITORY }}:${{ github.sha }} \ | ||
${{ env.DOCKER_REPOSITORY }}:${{ github.sha }}-amd64 \ | ||
${{ env.DOCKER_REPOSITORY }}:${{ github.sha }}-arm64 | ||
- name: Inspect image | ||
run: | | ||
docker buildx imagetools inspect ${{ env.DOCKER_REPOSITORY }}:latest | ||
docker buildx imagetools inspect ${{ env.DOCKER_REPOSITORY }}:${{ github.sha }} |
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
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,42 @@ | ||
# Start with the official MongoDB image | ||
FROM mongo:latest | ||
|
||
# Install Node.js and Git | ||
RUN apt-get update && \ | ||
apt-get install -y curl gnupg git && \ | ||
curl -sL https://deb.nodesource.com/setup_18.x | bash - && \ | ||
apt-get install -y nodejs | ||
|
||
# Install yarn globally | ||
RUN npm install -g yarn | ||
|
||
# Install pm2 globally | ||
RUN yarn global add pm2 | ||
|
||
# Copy in mailserver dependencies | ||
COPY mailserver/package.json /React-TrashMail/mailserver/ | ||
COPY mailserver/yarn.lock /React-TrashMail/mailserver/ | ||
COPY mailserver/node_modules /React-TrashMail/mailserver/node_modules | ||
|
||
# Copy the rest of the application code | ||
COPY . /React-TrashMail | ||
|
||
# Copy built React app to mailserver build directory | ||
COPY react/build /React-TrashMail/mailserver/build | ||
|
||
# Define mountable volume | ||
VOLUME ["/React-TrashMail/mailserver/attachments"] | ||
|
||
# Copy startup script | ||
COPY docker_start.sh /docker_start.sh | ||
RUN chmod +x /docker_start.sh | ||
|
||
# Set the health check | ||
COPY healthcheck.sh /healthcheck.sh | ||
RUN chmod +x /healthcheck.sh | ||
|
||
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ | ||
CMD /healthcheck.sh | ||
|
||
# Set the command to start the application using the startup script | ||
CMD ["/docker_start.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
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,16 @@ | ||
#!/bin/bash | ||
|
||
# Check MongoDB | ||
if ! mongosh --eval "db.adminCommand('ping')" > /dev/null 2>&1; then | ||
echo "MongoDB is down" | ||
exit 1 | ||
fi | ||
|
||
# Check Backend | ||
if ! curl -f http://localhost:4000/ > /dev/null 2>&1; then | ||
echo "Backend is down" | ||
exit 1 | ||
fi | ||
|
||
echo "All services are running" | ||
exit 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
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
Binary file not shown.
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
Oops, something went wrong.