Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
262ee5a
[wip] devcontainer
oestoer Jan 14, 2024
0730f71
add devcontainer and postgres
oestoer Feb 10, 2024
4055878
add perl libs to container
oestoer Feb 10, 2024
6ef5f43
fix typo
oestoer Feb 10, 2024
8fcdbbf
reduce image layers and remove apt cache
oestoer Feb 10, 2024
19fd49f
set access system dev image as devcontainer base
oestoer Feb 17, 2024
2807867
highlight code examples in readme
oestoer Feb 22, 2024
3771dff
remove not needed Dockerfile from .devcontainer folder
oestoer Feb 22, 2024
3bb095b
Add libpq-dev for PostgreSQL support and swmakers user
oestoer Feb 22, 2024
02b0101
Update CPAN dependencies and versions
oestoer Feb 22, 2024
fe5821d
Add support for SQLite database in Dockerfile
oestoer Feb 22, 2024
efc1d32
Update devcontainer.json with new name and forwardPorts
oestoer Feb 22, 2024
d014c0a
Fix COPY commands in Dockerfile to ensure proper file structure
oestoer Dec 11, 2024
c36d90b
Build Docker image with caching support
oestoer Dec 11, 2024
4e7632a
Add support for versioned tags in build workflow
oestoer Dec 11, 2024
a19bf51
Refactor GitHub Actions workflow to generate Docker metadata and impr…
oestoer Dec 12, 2024
7afe7ee
Add step to retrieve and sanitize branch name in build workflow
oestoer Dec 12, 2024
c1df5c1
Enable pushing of Docker images in build workflow
oestoer Dec 12, 2024
c754255
Remove dependencies from cpanfile.snapshot
oestoer Dec 12, 2024
0d33e55
Refactor Dockerfile to streamline user setup and permissions
oestoer Dec 22, 2024
5d93717
Refactor Dockerfile to set and use CATALYST_HOME variable
oestoer Dec 22, 2024
dc4cc16
Remove unused services and comments from docker-compose.yaml
oestoer Dec 23, 2024
ace9d1a
Remove duplicate dependency from cpanfile
oestoer Dec 23, 2024
d8183fc
Add MailHog service
oestoer Dec 23, 2024
c8aaf82
Add configuration files and scripts for development environment setup
oestoer Dec 23, 2024
2011001
Remove unused port mapping for MailHog service in docker-compose.yaml
oestoer Dec 23, 2024
5d5aef4
Remove unused access system configuration files
oestoer Dec 23, 2024
27ed309
Update OneAll configuration for development environment
oestoer Dec 29, 2024
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
20 changes: 20 additions & 0 deletions Dockerfile → .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@

FROM mcr.microsoft.com/devcontainers/base:buster

ENV CATALYST_HOME="/workspaces/AccessSystem"
ENV PATH="${CATALYST_HOME}/local/bin:${PATH}"

WORKDIR /workspaces/AccessSystem

RUN groupadd --gid 1001 swmakers \
&& useradd --uid 1001 --gid swmakers --shell /bin/bash --create-home swmakers

RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends \
perl=5.28.1-6+deb10u1 \
Expand Down Expand Up @@ -32,6 +40,9 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
libtimedate-perl \
liburi-perl \
libscalar-list-utils-perl \
# database support
libpq-dev \
sqlite3 \
&& cpanm -S Carton \
# for Perl::LanguageServer
&& apt-get -y install --no-install-recommends \
Expand All @@ -46,3 +57,12 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
libcoro-perl \
&& cpanm Perl::LanguageServer \
&& rm -rf /var/lib/apt/lists/*

COPY cpanfile* "${CATALYST_HOME}/"
COPY vendor/ "${CATALYST_HOME}/vendor/"

RUN chown -R swmakers:swmakers "${CATALYST_HOME}"

USER swmakers

RUN carton install --cached
30 changes: 30 additions & 0 deletions .devcontainer/config/accesssystem_api.conf.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using_frontend-proxy 1

<HTML::FormHandlerX::Field::noCAPTCHA>
site_key 6LdHZx0TAAAAAMuUdG-NScgCCbJ_HMyL1bdeM9vp
secret_key 6LdHZx0TAAAAAEAnQyttqqhDkEVXfUcsnDLPGmvi
</HTML::FormHandlerX::Field::noCAPTCHA>
<View::Email>
<sender>
mailer SMTP
<mailer_args>
host mailhog
port 1025
helo localhost
sasl_username info@swindon-makerspace.org
sasl_password password
debug 1
</mailer_args>
</sender>
</View::Email>
<OneAll>
subdomain swindon-makerspace
domain mock-login:8080
public_key <not-needed-for-dev>
private_key <not-needed-for-dev>
callback_url http://access-system/oneall_login_callback
</OneAll>
<authen_cookie>
name access_system
mac_secret C7B626AC-87A8-4C10-B5CC-D98BED2DBE0B
</authen_cookie>
10 changes: 10 additions & 0 deletions .devcontainer/config/accesssystem_api_local.conf.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Model::AccessDB>
<connect_info>
dsn DBI:SQLite:db/dev.db
</connect_info>
</Model::AccessDB>
<Sendinblue>
api-key <look this up>
</Sendinblue>
base_url http://localhost:3000/
overlap_days 14
71 changes: 71 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-docker-compose
{
"name": "Swindon Makerspace Access System devcontainer",

// Update the 'dockerComposeFile' list if you have more compose files or use different names.
// The .devcontainer/docker-compose.yml file contains any overrides you need/want to make.
"dockerComposeFile": [
"../docker-compose.yaml",
"docker-compose.yaml"
],

// The 'service' property is the name of the service for the container that VS Code should
// use. Update this value and .devcontainer/docker-compose.yml to the real service name.
"service": "access-system",

// The optional 'workspaceFolder' property is the path VS Code should open by default when
// connected. This is typically a file mount in .devcontainer/docker-compose.yml
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",

// Features to add to the dev container. More info: https://containers.dev/features.
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {
"installZsh": true,
"configureZshAsDefaultShell": true,
"installOhMyZsh": true,
"installOhMyZshConfig": true,
"upgradePackages": true,
"username": "automatic",
"userUid": "automatic",
"userGid": "automatic"
},
"ghcr.io/devcontainers/features/github-cli:1": {
"installDirectlyFromGitHubRelease": true,
"version": "latest"
}
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [3000, 3001],

// Uncomment the next line if you want start specific services in your Docker Compose config.
// "runServices": [],

// Uncomment the next line if you want to keep your containers running after VS Code shuts down.
// "shutdownAction": "none",

// Run commands after the container is created.
"postCreateCommand": ".devcontainer/init-sqlite -d dev.db",
"postStartCommand": ".devcontainer/start-services",

// Configure tool-specific properties.
"customizations": {
"vscode": {
"extensions": [
"richterger.perl",
"cfgweb.vscode-perl",
"tamasfe.even-better-toml",
"maattdd.gitless",
"EditorConfig.EditorConfig"
]
},
"jetbrains" : {
"settings": {
"com.intellij:app:HttpConfigurable.use_proxy_pac": true
},
"backend" : "IntelliJ"
},
},
"remoteUser": "swmakers"
}
24 changes: 24 additions & 0 deletions .devcontainer/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
services:
access-system:
# We use a pre-built image to save time. You can also use a Dockerfile to build your own.
# Uncomment if you want to override the service's image with the Dockerfile in the .devcontainer
# folder. Note that the path of the Dockerfile and context is relative to the *primary*
# docker-compose.yml file (the first in the devcontainer.json "dockerComposeFile"
# array). The sample below assumes your primary file is in the root of your project.
#
# build:
# context: .
# dockerfile: .devcontainer/Dockerfile

volumes:
# Update this to wherever you want VS Code to mount the folder of your project
- ..:/workspaces:cached

# Uncomment the next four lines if you will use a ptrace-based debugger like C++, Go, and Rust.
# cap_add:
# - SYS_PTRACE
# security_opt:
# - seccomp:unconfined

# Overrides default command so things don't shut down after the process ends.
command: /bin/sh -c "while sleep 1000; do :; done"
33 changes: 33 additions & 0 deletions .devcontainer/init-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

# Define the source and destination directories
src_dir="$(dirname "$0")/config"
dest_dir="$(dirname "$0")/.."

# Find all .conf.dev files in the source directory
IFS=$'\n' read -rd '' -a config_files <<< "$(find "$src_dir" -name "*.conf.dev" -exec basename {} \;)"

# Function to copy and rename files
copy_and_rename() {
local src_file="$1"
local dest_file="$2"

if [ ! -f "$dest_file" ]; then
cp "$src_file" "$dest_file"
echo "Copied $src_file to $dest_file"
else
echo "File $dest_file already exists, not overwriting"
fi
}

# Process each config file
for config_file in "${config_files[@]}"; do
src_file="$src_dir/$config_file"
dest_file="$dest_dir/${config_file%.dev}"

if [ -f "$src_file" ]; then
copy_and_rename "$src_file" "$dest_file"
else
echo "Source file $src_file does not exist"
fi
done
86 changes: 86 additions & 0 deletions .devcontainer/init-sqlite
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/bin/sh

# Function to display usage
usage() {
echo "Initialize an SQLite database for development in db/ folder\n"
echo "Options:"
echo "\t -d <sqlite_db_filename>, e.g. dev.db"
echo "\t -f Force recreate the database file if it exists"
echo "\nUsage: $0 -d <sqlite_db_filename> [-f]"
exit 1
}

force_recreate=false

# Parse command line arguments
while getopts ":d:f" opt; do
case ${opt} in
d )
db_filename=$OPTARG
;;
f )
force_recreate=true
;;
\? )
usage
;;
esac
done

# Check if the db_filename is provided
if [ -z "$db_filename" ]; then
usage
fi

# Check if the filename ends with .db
if [ "${db_filename##*.}" != "db" ]; then
echo "Error: The database filename must end with .db"
usage
fi

# Create the db folder if it doesn't exist
db_folder="$(dirname "$0")/../db"
mkdir -p "$db_folder"

# Create the SQLite database file
db_path="$db_folder/$db_filename"

# Check if the database file already exists
if [ -f "$db_path" ]; then
if [ "$force_recreate" = true ]; then
# Create a backup of the existing database file with the current date and time
timestamp=$(date +"%Y-%m-%d_%H:%M")
cp "$db_path" "$db_path.$timestamp.bak"
echo "Existing database file backed up as $db_filename.$timestamp.bak"
else
echo "Database file $db_filename already exists. Use -f to force recreate."
exit 0
fi
fi

# Create or overwrite the SQLite database file
sqlite3 "$db_path" "VACUUM;"

# Find the latest SQLite schema file
sql_folder="$(dirname "$0")/../sql"
latest_sql_file=$(ls -1t "$sql_folder"/AccessSystem-Schema*SQLite.sql | head -n 1)

# Check if the latest SQL file is found
if [ -z "$latest_sql_file" ]; then
echo "No SQLite schema file found in $sql_folder"
exit 1
fi

# Run the latest SQL schema file on the database
echo "Initializing database $db_filename with $latest_sql_file...\n"
sqlite3 "$db_path" -cmd ".echo on" ".read $latest_sql_file"

echo "\nDatabase $db_filename created and initialized with $latest_sql_file"

# use the .devcontainer/seed-sqlite.sql file to populate the database
seed_sql_file="$(dirname "$0")/seed-sqlite.sql"
if [ -f "$seed_sql_file" ]; then
echo "Seeding database $db_filename with $seed_sql_file...\n"
sqlite3 "$db_path" -cmd ".echo on" ".read $seed_sql_file"
echo "\nDatabase $db_filename seeded with $seed_sql_file"
fi
14 changes: 14 additions & 0 deletions .devcontainer/seed-sqlite.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
INSERT INTO tiers (id, name, description, price, concessions_allowed, in_use, restrictions)
VALUES (4, 'Sponsor', 'Access 24hours a day, 365 days a year', 3500, true, true, '{}');
INSERT INTO tiers (id, name, description, price, concessions_allowed, in_use, restrictions)
VALUES (3, 'Standard', 'Access 24hours a day, 365 days a year', 2500, true, true, '{}');
INSERT INTO tiers (id, name, description, price, concessions_allowed, in_use, restrictions)
VALUES (1, 'MemberOfOtherHackspace',
'Living outside of Swindon Borough and a fully paid up member of another Maker or Hackspace', 500, false, true,
'{}');
INSERT INTO tiers (id, name, description, price, concessions_allowed, in_use, restrictions)
VALUES (2, 'Weekend', 'Access 12:00am Saturday until 12:00am Monday, and Wednesdays 6:30pm to 11:59pm only', 1500, true,
true,
'{"times":[{"from":"3:18:00","to":"3:23:59"},{"from":"6:00:01","to":"6:23:59"},{"from":"7:00:01","to":"7:23:59"}]}');
INSERT INTO tiers (id, name, description, price, concessions_allowed, in_use, restrictions)
VALUES (5, 'MensShed', 'Members of Renew only, rate now retired', 1000, false, false, '{}');
17 changes: 17 additions & 0 deletions .devcontainer/start-services
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

export PERL5LIB="/workspace/AccessSystem/local/lib/perl5/"
# export PATH="/workspace/AccessSystem/local/bin:${PATH}"

echo "Initializing service configuration..."
.devcontainer/init-config

echo "Starting services in the background..."

echo "Starting database admin (RapidApp) @ http://localhost:3001/admin"
carton exec perl script/accesssystem_daemon_devcontainer.pl start

echo "Starting API server @ http://localhost:3000"
carton exec perl script/accesssystem_api_daemon_devcontainer.pl start

echo "It may take a few seconds for the services to be up. Please wait..."
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for more information:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
# https://containers.dev/guide/dependabot

version: 2
updates:
- package-ecosystem: "devcontainers"
directory: "/"
schedule:
interval: weekly
Loading
Loading