Skip to content

Commit

Permalink
Merge pull request #5378 from DFE-Digital/3847-fix-codespaces
Browse files Browse the repository at this point in the history
Fix GitHub codespaces
  • Loading branch information
ethax-ross authored Dec 20, 2024
2 parents 7092010 + 094e99e commit 0fc3cd5
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 25 deletions.
11 changes: 11 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
FROM mcr.microsoft.com/vscode/devcontainers/base:ubuntu-22.04

ENV RAILS_DEVELOPMENT_HOSTS=".githubpreview.dev,.app.github.dev" \
CODESPACES="true" \
DB_HOST="postgres" \
DB_USERNAME="postgres" \
DB_PASSWORD="postgres"

# Adding the PostgreSQL repository so we can install postgresql-client v15
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
RUN curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor -o /etc/apt/trusted.gpg.d/postgresql.gpg
22 changes: 15 additions & 7 deletions .devcontainer/boot.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
#!/bin/bash

echo "Setting SSH password for vscode user..."
sudo usermod --password $(echo vscode | openssl passwd -1 -stdin) vscode

echo "Updating RubyGems..."
gem update --system
gem update --system -N

echo "Installing dependencies..."
gem install bundler -v 2.4.14 # Must be explicitly specified or we get an error on the subsequent bundle install.
bundle install
yarn install
yarn build
yarn build:css

echo "Creating database..."
bin/rails db:create db:schema:load db:migrate db:seed
bin/rails db:create db:schema:load

echo "Seeding database..."
bin/rails db:seed

echo "Installing documentation dependencies..."
cd docs
gem install bundler -v 2.4.6 # Must be explicitly specified or we get an error on the subsequent bundle install.
bundle install

echo "Installing documentation dependencies"
cd docs && bundle
echo "Building documentation..."
bundle exec middleman build --build-dir=../public/api-reference

echo "Done!"
2 changes: 2 additions & 0 deletions .devcontainer/create-db-user.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE USER vscode CREATEDB;
CREATE DATABASE vscode WITH OWNER vscode;
35 changes: 21 additions & 14 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
"name": "Manage training for early career teachers",
"name": "Manage training for early career teachers",
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
"features": {
"ghcr.io/devcontainers/features/sshd:1": {},
"ghcr.io/rocker-org/devcontainer-features/apt-packages:1": {
"packages": "libpq-dev, libvips, entr"
"packages": "libpq-dev, libvips, postgresql-client-15, clang, entr"
},
"ghcr.io/devcontainers/features/git:1": {
"version": "latest"
Expand All @@ -17,32 +16,40 @@
"ghcr.io/devcontainers/features/node:1": {
"version": "18.18"
},
"ghcr.io/devcontainers/features/common-utils:1": {
"ghcr.io/devcontainers/features/common-utils:2": {
"username": "vscode",
"uid": 1000,
"gid": 1000,
"userUid": 1000,
"userGid": 1000,
"installZsh": true,
"installOhMyZsh": true,
"configureZshAsDefaultShell": true,
"upgradePackages": true
},
"ghcr.io/devcontainers-contrib/features/zsh-plugins:0": {
"username": "vscode",
"plugins": "bundler rails ruby yarn"
},
"ghcr.io/devcontainers/features/sshd:1": {
"version": "latest"
}
},

// Configure tool-specific properties.
"customizations": {
"vscode": {
"extensions": [
"Shopify.ruby-lsp",
"esbenp.prettier-vscode",
"ms-vscode.vscode-typescript-tslint-plugin",
"ms-vscode.vscode-types"
]
"extensions": ["Shopify.ruby-lsp", "EditorConfig.EditorConfig"]
}
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// This can be used to network with other containers or the host.
"forwardPorts": [2222],
"forwardPorts": [5432],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": ".devcontainer/boot.sh"
"postCreateCommand": ".devcontainer/boot.sh",

"postStartCommand": "bin/dev"

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
9 changes: 5 additions & 4 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3'

services:
app:
build:
Expand All @@ -9,16 +7,19 @@ services:
- ../..:/workspaces:cached
command: sleep infinity
postgres:
image: postgres:15-alpine
image: postgres:latest
restart: unless-stopped
volumes:
- postgres-data:/var/lib/postgresql/data
- ./create-db-user.sql:/docker-entrypoint-initdb.d/create-db-user.sql
ports:
- 5432
environment:
POSTGRES_USER: postgres
POSTGRES_DB: postgres
POSTGRES_PASSWORD: postgres
redis:
image: redis:7-alpine
image: redis:7.2-alpine
restart: unless-stopped
volumes:
- redis-data:/data
Expand Down
6 changes: 6 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,10 @@

# Raise error when a before_action's only/except options reference missing actions
config.action_controller.raise_on_missing_callback_actions = true

# Disable origin check for Cross-Site Request Forgery (CSRF) protection for Codespaces.
# I'm not sure why it doesn't work, but it doesn't.
if ENV["CODESPACES"].present?
config.action_controller.forgery_protection_origin_check = false
end
end

0 comments on commit 0fc3cd5

Please sign in to comment.