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

WIP: Feature/add devcontainer configuration #54

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
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
32 changes: 32 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
services:
podverse_web:
# TODO uncomment image before merging
# image: ghcr.io/podverse/podverse-web-dev
build:
context: ../../.github/.devcontainer/podverse-web/
command: sleep infinity
user: node
volumes:
- type: bind
source: ../..
target: /workspaces
bind:
selinux: z
create_host_path: false
working_dir: /workspaces/projects/podverse-web

podverse_api:
# TODO uncomment image before merging
# image: ghcr.io/podverse/podverse-api-dev
build:
context: ../../.github/.devcontainer/podverse-api/
command: sleep infinity
user: node
volumes:
- type: bind
source: ../..
target: /workspaces
bind:
selinux: z
create_host_path: false
working_dir: /workspaces/projects/podverse-api
49 changes: 49 additions & 0 deletions .devcontainer/podverse-api/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"name": "Podverse API",
"dockerComposeFile": [
"../../docker-compose/local/docker-compose.yml",
"../docker-compose.yml"
],
"service": "podverse_api",
"workspaceFolder": "/workspaces/projects/podverse-api",
"features": {
"ghcr.io/devcontainers/features/common-utils": {},
"ghcr.io/devcontainers-extra/features/prettier": {},
"ghcr.io/robbert229/devcontainer-features/postgresql-client:1": {
"version": "16"
}
},
"portsAttributes": {
"3000": {
"label": "Podverse Web",
"onAutoForward": "openBrowserOnce"
},
"1234": {
"label": "Podverse API"
},
"5432": {
"label": "Podverse Database"
},
"9306": {
"label": "Manticore"
},
"9308": {
"label": "Manticore"
}
},
"runServices": ["podverse_web", "podverse_db", "podverse_manticore"],
// Uncomment the next line if you want to keep your containers running after VS Code shuts down.
// This is needed if you have a multi-container dev environment with frontend and backend.
// You will need to manually shutdown containers when you're done.
"shutdownAction": "none"

// Uncomment the next line to run commands after the container is created.
// "postCreateCommand": "cat /etc/os-release",
// "onCreateCommand": "make local_git_sub_init"

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "devcontainer"
}
47 changes: 47 additions & 0 deletions .devcontainer/podverse-web/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "Podverse Web",
"dockerComposeFile": [
"../../docker-compose/local/docker-compose.yml",
"../docker-compose.yml"
],
"service": "podverse_web",
"workspaceFolder": "/workspaces/projects/podverse-web",
"features": {
"ghcr.io/devcontainers/features/common-utils": {},
"ghcr.io/devcontainers-extra/features/prettier": {},
"ghcr.io/robbert229/devcontainer-features/postgresql-client:1": {
"version": "16"
}
},
"portsAttributes": {
"3000": {
"label": "Podverse Web",
"onAutoForward": "openBrowserOnce"
},
"1234": {
"label": "Podverse API"
},
"5432": {
"label": "Podverse Database"
},
"9306": {
"label": "Manticore"
},
"9308": {
"label": "Manticore"
}
},
"runServices": ["podverse_api", "podverse_db", "podverse_manticore"],

// Uncomment the next line if you want to keep your containers running after VS Code shuts down.
// This is needed if you have a multi-container dev environment with frontend and backend.
// You will need to manually shutdown containers when you're done.
"shutdownAction": "none"

// Uncomment the next line to run commands after the container is created.
// "postCreateCommand": "cat /etc/os-release",
// "onCreateCommand": "make local_git_sub_init"

// Configure tool-specific properties.
// "customizations": {},
}
20 changes: 20 additions & 0 deletions .github/.devcontainer/podverse-api/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM mcr.microsoft.com/devcontainers/typescript-node:1-20-bookworm
# TODO switch to this before merging
# FROM ghcr.io/podverse/podverse-web-dev:latest

# Update the package listing, so we know what package exist:
RUN apt-get update \
&& apt-get -y upgrade \
&& apt-get -y install --no-install-recommends podman slirp4netns systemd uidmap \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Create symbolic link so docker commands are handled as podman commands
RUN ln -s /usr/bin/podman /usr/bin/docker

# create api_user but don't set the container user
RUN adduser --disabled-login --gecos api_user api_user

LABEL org.opencontainers.image.source=https://github.com/podverse/podverse-ops
LABEL org.opencontainers.image.description="Podverse API Devcontainer"
LABEL org.opencontainers.image.licenses=AGPLv3
14 changes: 14 additions & 0 deletions .github/.devcontainer/podverse-api/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "Podverse API",
"build": {
"dockerfile": "./Dockerfile",
"context": "."
},
"features": {
"ghcr.io/devcontainers/features/common-utils": {},
"ghcr.io/devcontainers-extra/features/prettier": {},
"ghcr.io/robbert229/devcontainer-features/postgresql-client:1": {
"version": "16"
}
}
}
5 changes: 5 additions & 0 deletions .github/.devcontainer/podverse-web/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM mcr.microsoft.com/devcontainers/typescript-node:1-20-bookworm

LABEL org.opencontainers.image.source=https://github.com/podverse/podverse-ops
LABEL org.opencontainers.image.description="Podverse Web Devcontainer"
LABEL org.opencontainers.image.licenses=AGPLv3
14 changes: 14 additions & 0 deletions .github/.devcontainer/podverse-web/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "Podverse Web",
"build": {
"dockerfile": "./Dockerfile",
"context": "."
},
"features": {
"ghcr.io/devcontainers/features/common-utils": {},
"ghcr.io/devcontainers-extra/features/prettier": {},
"ghcr.io/robbert229/devcontainer-features/postgresql-client:1": {
"version": "16"
}
}
}
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
41 changes: 41 additions & 0 deletions .github/workflows/devcontainer-build-and-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Dev Container Build and Push Image

on:
workflow_dispatch:
push:
branches:
- "master"
tags:
- "v*.*.*"
pull_requests:
branches:
- "master"
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.REGISTRY_TOKEN }}
- name: Pre-build Web devcontainer image
uses: devcontainers/[email protected]
with:
subFolder: .github
configFile: .github/.devcontainer/podverse-web/devcontainer.json
imageName: ghcr.io/${{ github.actor }}/podverse-web-dev
cacheFrom: ghcr.io/${{ github.actor }}/podverse-web-dev
push: always
- name: Pre-build API devcontainer image
uses: devcontainers/[email protected]
with:
subFolder: .github
configFile: .github/.devcontainer/podverse-api/devcontainer.json
imageName: ghcr.io/${{ github.actor }}/podverse-api-dev
cacheFrom: ghcr.io/${{ github.actor }}/podverse-api-dev
push: always
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
[submodule "projects/podverse-web"]
path = projects/podverse-web
url = https://github.com/podverse/podverse-web.git
branch = develop
ignore = all
[submodule "projects/podverse-api"]
path = projects/podverse-api
url = https://github.com/podverse/podverse-api.git
branch = develop
ignore = all
31 changes: 31 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -322,3 +322,34 @@ sanbox_srv_docker-compose_up:
.PHONY: sanbox_srv_docker-compose_up-no_dettach
sanbox_srv_docker-compose_up-no_dettach:
docker-compose -f docker-compose/sandbox/srv/docker-compose.yml up

.PHONY: dev_up
dev_up:
@echo 'Starting devcontainers'
@devcontainer up --prebuild --workspace-folder . --config .devcontainer/podverse-web/devcontainer.json
@devcontainer set-up --config .devcontainer/podverse-api/devcontainer.json --container-id podverse_api_local

.PHONY: dev_down
dev_down:
@echo 'Stopping devcontainers'
@docker compose -f ./docker-compose/local/docker-compose.yml -f ./.devcontainer/docker-compose.yml down

.PHONY: dev_start_api
dev_start_api:
@echo 'Starting Podverse API node server'
@devcontainer exec --config .devcontainer/podverse-api/devcontainer.json --container-id podverse_api_local yarn start

.PHONY: dev_start_web
dev_start_web:
@echo 'Starting Podverse Web node server'
@devcontainer exec --config .devcontainer/podverse-web/devcontainer.json --container-id podverse_web_local yarn start

.PHONY: dev_shell_api
dev_shell_api:
@echo 'Shelling into api container'
@devcontainer exec --config .devcontainer/podverse-api/devcontainer.json --container-id podverse_api_local bash

.PHONY: dev_shell_web
dev_shell_web:
@echo 'Shelling into web container'
@devcontainer exec --config .devcontainer/podverse-web/devcontainer.json --container-id podverse_web_local bash
4 changes: 4 additions & 0 deletions config/podverse-api-local.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#####
##### App / General
#####
# Set NODE_ENV to development when using dev containers
NODE_ENV=production
PORT=1234
JWT_SECRET=your-secret-whatever
Expand All @@ -26,6 +27,7 @@ USER_AGENT=Podverse/Feed Parser

# Use the public facing domain, not the internal docker network ip address.
COOKIE_DOMAIN=localhost
# for local dev setting this to false is probably ok
COOKIE_IS_SECURE=

# Some endpoints use RateLimiter middleware to prevent spamming requests.
Expand Down Expand Up @@ -181,6 +183,8 @@ SHRUNK_IMAGE_SIZE=800
##### FCM Google
#####
### We use FCM to send push notifications.
# in the devcontainer set this to /workspaces/config/google/jwt.keys.json
# follow the guide to get your key in podverse-ops/config/google/Firebase API key.md
FCM_GOOGLE_API_AUTH_TOKEN=

#####
Expand Down
4 changes: 2 additions & 2 deletions config/podverse-web-local.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#####
##### App / General
#####

NODE_ENV=develop
# set NODE_ENV to devlopment when using dev containers
NODE_ENV=production
PORT=3000

API_PROTOCOL=http
Expand Down
2 changes: 1 addition & 1 deletion db/old-sample-database/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
FROM postgres:11.5
FROM postgres:16.5-bookworm
ADD ./old-sample-database.sql.gz /docker-entrypoint-initdb.d
2 changes: 1 addition & 1 deletion db/qa-database/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
FROM postgres:11.5
FROM postgres:16.5-bookworm
ADD ./qa-database.sql.gz /docker-entrypoint-initdb.d
2 changes: 1 addition & 1 deletion db/schema-only/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
FROM postgres:11.5
FROM postgres:16.5-bookworm
ADD ./schema-only.sql.gz /docker-entrypoint-initdb.d
8 changes: 4 additions & 4 deletions docker-compose/local/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ services:
max-size: '50m'

podverse_api:
build: ./projects/podverse-api
build: ../projects/podverse-api
container_name: podverse_api_local
privileged: true
depends_on:
Expand All @@ -104,7 +104,7 @@ services:
max-size: "50m"

podverse_web:
build: ./projects/podverse-web
build: ../projects/podverse-web
container_name: podverse_web_local
depends_on:
# - podverse_nginx_proxy
Expand All @@ -125,7 +125,7 @@ services:
max-size: "50m"

podverse_api_worker:
build: ./projects/podverse-api
build: ../projects/podverse-api
container_name: podverse_api_worker_local
env_file:
- ../../config/podverse-api-local.env
Expand All @@ -136,7 +136,7 @@ services:
max-size: "50m"

podverse_maintenance_mode_web:
build: ./projects/podverse-web/maintenance_mode
build: ../projects/podverse-web/maintenance_mode
container_name: podverse_maintenance_mode_web_local
# depends_on:
# - podverse_nginx_proxy
Expand Down