Skip to content

Commit

Permalink
- fly.io deploy and workflow
Browse files Browse the repository at this point in the history
- added chrome and chromedriver to the Dockerfile
- parameterised CHROMEDRIVER_VERSION, CHROME_VERSION in Dockerfile
- reflect chrome / driver environment changes in protractor.conf.js
- allow group name to be passed in via APP_NAME secret
- perform fly.toml replacements for DOCKER_IMAGE and APP_NAME variables
- adding allowed domains
  • Loading branch information
nbarrett committed Sep 21, 2024
1 parent 4437d7d commit f504228
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin

- name: Build the Docker image
run: docker build . --file Dockerfile --tag ngx-ramblers:${{ github.run_number }}
run: docker build . --build-arg CHROME_VERSION=${{ secrets.CHROME_VERSION }} --build-arg CHROMEDRIVER_VERSION=${{ secrets.CHROMEDRIVER_VERSION }} --file Dockerfile --tag ngx-ramblers:${{ github.run_number }}

- name: Tag the Docker image (github run number ${{ github.run_number }})
run: docker tag ngx-ramblers:${{ github.run_number }} ${{ secrets.DOCKER_USERNAME }}/ngx-ramblers:${{ github.run_number }}
Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/fly-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Fly Deploy

on:
workflow_dispatch:
push:
branches: [ "fly-deploy" ]
pull_request:
branches: [ "fly-deploy" ]

jobs:
deploy:
name: Deploy app
runs-on: ubuntu-latest
concurrency: deploy-group
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set environment variables
run: |
echo "APP_NAME=${{ secrets.APP_NAME }}" >> $GITHUB_ENV
echo "DOCKER_USERNAME=${{ secrets.DOCKER_USERNAME }}" >> $GITHUB_ENV
echo "DOCKER_IMAGE=${{ secrets.DOCKER_USERNAME }}/ngx-ramblers:latest" >> $GITHUB_ENV
echo "ALLOWED_DOMAINS=${{ secrets.ALLOWED_DOMAINS }}" >> $GITHUB_ENV # Add this line
- name: Replace Docker image, app name, and allowed domains in fly.toml
run: |
sed -i 's|\${DOCKER_IMAGE}|'"$DOCKER_IMAGE"'|g' fly.toml
sed -i 's|\${APP_NAME}|'"$APP_NAME"'|g' fly.toml
sed -i 's|\${ALLOWED_DOMAINS}|'"$ALLOWED_DOMAINS"'|g' fly.toml
- name: Install Flyctl
uses: superfly/flyctl-actions/setup-flyctl@master

- name: Deploy App
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
run: flyctl deploy --remote-only --app $APP_NAME

- name: Scale App to 1
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
run: flyctl scale count 1 --app $APP_NAME
25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
# Use the official Node.js image as the base image
FROM node:20.11.0

# Define build arguments
ARG CHROME_VERSION
ARG CHROMEDRIVER_VERSION

# Install dependencies for Chrome installation
RUN apt-get update && apt-get install -y wget curl unzip gnupg2 ca-certificates

# Add Google Chrome repository
RUN wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
RUN apt-get update && apt-get install -y google-chrome-stable

# Download the specified version of Chrome for Testing and its Chromedriver
RUN curl -Lo /tmp/chrome.zip "https://storage.googleapis.com/chrome-for-testing-public/${CHROME_VERSION}/linux64/chrome-linux64.zip" && \
curl -Lo /tmp/chromedriver.zip "https://storage.googleapis.com/chrome-for-testing-public/${CHROMEDRIVER_VERSION}/linux64/chromedriver-linux64.zip" && \
unzip /tmp/chrome.zip -d /usr/local/ && \
unzip /tmp/chromedriver.zip -d /usr/local/bin/ && \
rm /tmp/chrome.zip /tmp/chromedriver.zip

# Add Chrome to PATH
ENV CHROME_BIN=/usr/local/chrome-linux64/chrome

# Set CHROMEDRIVER_PATH environment variable
ENV CHROMEDRIVER_PATH=/usr/local/bin/chromedriver

# Set the working directory inside the container
WORKDIR /usr/src/app

Expand Down
22 changes: 22 additions & 0 deletions fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# fly.toml app configuration file generated for ngx-ramblers
app = "${APP_NAME}"
primary_region = "lhr"

[build]
image = "${DOCKER_IMAGE}"

[http_service]
internal_port = 5000
force_https = true
auto_stop_machines = "stop"
auto_start_machines = true
min_machines_running = 0
processes = ["app"]

[[http_service.allow_origin]]
origin = "${ALLOWED_DOMAINS}"

[[vm]]
memory = "1gb"
cpu_kind = "shared"
cpus = 1
4 changes: 2 additions & 2 deletions server/protractor.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ const path = require('path'),
{SerenityBDDReporter} = require("@serenity-js/serenity-bdd");

exports.config = {
chromeDriver: process.env["CHROMEDRIVER_PATH"] || require('chromedriver/lib/chromedriver').path,
chromeDriver: process.env["CHROMEDRIVER_PATH"] || "/usr/local/bin/chromedriver",
SELENIUM_PROMISE_MANAGER: false,
directConnect: true,
baseUrl: "https://ekwg-dev.herokuapp.com",
baseUrl: process.env["BASE_URL"],
allScriptsTimeout: 110000,
getPageTimeout: 60000,

Expand Down

0 comments on commit f504228

Please sign in to comment.