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

Bump jsdom and react-scripts #17

Open
wants to merge 2 commits into
base: main
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
26 changes: 26 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Build and Deploy

on:
push:
branches: [main]

jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Build Docker image
run: docker build -t qcext-server .

- name: Save Docker image
run: docker save -o qcext-server.tar qcext-server

- name: Compress Docker image
run: bzip2 -z qcext-server.tar

- name: Deploy
run: docker-compose run deploy
env:
DEPLOY_KEY: ${{ secrets.deploy_key }}
DEPLOY_TARGET: ${{ secrets.deploy_target }}
1 change: 0 additions & 1 deletion .npmrc

This file was deleted.

50 changes: 36 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
FROM rust:latest AS build
##################
# Rust image #
##################

FROM rust:latest AS rust

WORKDIR /usr/src/qcext-server

# Run SQLX in offline mode
ENV SQLX_OFFLINE=true

# Make sure we have npm and nodejs
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
nodejs npm
RUN nodejs --version
RUN npm --version

# Build the dependencies in a separate step to avoid rebuilding all of them
# every time the source code changes. This takes advantage of Docker's layer
# caching, and it works by doing a build using the Cargo.{toml,lock} files with
Expand All @@ -29,22 +27,46 @@ RUN mkdir -p /usr/src/qcext-server/shared/src && \
RUN cargo fetch
RUN cargo build --release

# Next, let's run npm install
COPY package.json .npmrc /usr/src/qcext-server/
RUN npm install

# Dependencies are now cached, copy the actual source code and do another full
# build. The touch on all the .rs files is needed, otherwise cargo assumes the
# source code didn't change thanks to mtime weirdness.
RUN rm -rf /usr/src/qcext-server/src /usr/src/qcext-server/database/src /usr/src/qcext-server/shared/src
COPY src /usr/src/qcext-server/src
RUN rm -rf /usr/src/qcext-server/src/client
COPY database/src /usr/src/qcext-server/database/src
COPY shared/src /usr/src/qcext-server/shared/src
RUN find src -name "*.rs" -exec touch {} \; && \
find database/src -name "*.rs" -exec touch {} \; && \
find shared/src -name "*.rs" -exec touch {} \; && \
cargo build --release

##################
# NodeJS image #
##################

FROM debian:bullseye AS nodejs

WORKDIR /usr/src/qcext-server

# Make sure we have npm and nodejs
RUN apt-get update
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y curl
RUN curl -fsSL https://deb.nodesource.com/setup_lts.x | bash -
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y nodejs
RUN node --version
RUN npm --version

# Next, let's run npm install
COPY package.json package-lock.json /usr/src/qcext-server/
RUN npm install

# Copy only files relevant for Node (i.e. no Rust files)
RUN mkdir /usr/src/qcext-server/src
COPY src/client /usr/src/qcext-server/src/client
COPY src/index.js /usr/src/qcext-server/src

RUN npx browserslist@latest --update-db

COPY public /usr/src/qcext-server/public
RUN npm run build

Expand All @@ -55,11 +77,11 @@ RUN npm run build
FROM debian:bullseye-slim AS binary

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
ca-certificates
ca-certificates rsync
RUN apt-get clean

COPY --from=build /usr/src/qcext-server/target/release/qcext-server /usr/local/bin/
COPY --from=build /usr/src/qcext-server/build /build
COPY --from=rust /usr/src/qcext-server/target/release/qcext-server /usr/local/bin/
COPY --from=nodejs /usr/src/qcext-server/build /build

ENV RUST_LOG=info
CMD ["/usr/local/bin/qcext-server"]
21 changes: 21 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh

# Instantly exits our script whenever an error occurs
set -e

# Pipe our environmental SSH key variable into a file
mkdir -p $HOME/.ssh
echo "${deploy_key}" > $HOME/.ssh/deploy_key
chmod 600 $HOME/.ssh/deploy_key # SSH keys need to be readonly

# Where to deploy our site on our server
target="/home/ec2-user/qcext-server/staging"

# The actual deployment
sh -c "rsync -azvh -e 'ssh -i $HOME/.ssh/deploy_key -o StrictHostKeyChecking=no' qcext-server.tar.bz2 ${deploy_target}:${target}"

# Run update script
sh -c "ssh -i $HOME/.ssh/deploy_key -o StrictHostKeyChecking=no ${deploy_target} 'cd ${target}; ./update.sh'"

# Remove our deploy_key again since it's no longer needed
rm $HOME/.ssh/deploy_key
12 changes: 12 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '3'

services:
deploy:
image: 'instrumentisto/rsync-ssh'
volumes:
- .:/home/site
working_dir: /home/site
environment:
deploy_key: $DEPLOY_KEY
deploy_target: $DEPLOY_TARGET
command: sh deploy.sh
Loading