Skip to content

Commit

Permalink
Merge pull request #18 from miztch/gorillamux
Browse files Browse the repository at this point in the history
refactor: rewrite with Go
  • Loading branch information
miztch authored Jul 9, 2024
2 parents 22d91bf + 461c109 commit 944b2fa
Show file tree
Hide file tree
Showing 27 changed files with 568 additions and 455 deletions.
23 changes: 9 additions & 14 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"name": "Python 3",
"image": "mcr.microsoft.com/devcontainers/python:1-3.11-bullseye",
"name": "Go Dev Container",
"image": "mcr.microsoft.com/devcontainers/go:1-1.21-bullseye",
"features": {
"ghcr.io/devcontainers/features/python:1": {
"version": "latest"
},
"ghcr.io/devcontainers/features/aws-cli:1": {},
"ghcr.io/customink/codespaces-features/sam-cli:1": {}
},
Expand All @@ -11,8 +14,8 @@
"amazonwebservices.aws-toolkit-vscode",
"esbenp.prettier-vscode",
"github.vscode-github-actions",
"ms-python.black-formatter",
"ms-python.isort",
"redhat.vscode-yaml",
"ms-vscode.makefile-tools",
"kddejong.vscode-cfn-lint",
"oderwat.indent-rainbow",
"github.copilot",
Expand All @@ -22,20 +25,12 @@
"terminal.integrated.shell.linux": "/usr/bin/zsh",
"[yaml]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[python]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "ms-python.black-formatter"
},
"isort.args": [
"--profile",
"black"
]
}
}
}
},
"mounts": [
"source=${env:HOME}${env:USERPROFILE}/.aws,target=/home/vscode/.aws,type=bind,consistency=cached"
],
"postCreateCommand": "pip install cfn-lint chalice"
"postCreateCommand": "pip install cfn-lint"
}
4 changes: 2 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

version: 2
updates:
- package-ecosystem: "pip"
directory: "/function"
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "weekly"
commit-message:
Expand Down
20 changes: 12 additions & 8 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,24 @@ on:
permissions:
id-token: write
contents: read

jobs:
build-and-deploy:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
environment: production
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install jq
uses: dcarbone/[email protected]
- name: Setup Python
uses: actions/setup-python@v5
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: "1.21.x"
- name: Setup AWS SAM CLI
uses: aws-actions/setup-sam@v2
with:
use-installer: true
- name: Setup AWS Credentials
uses: aws-actions/[email protected]
with:
Expand All @@ -35,10 +39,10 @@ jobs:
SASHA_TABLE_NAME=` \
aws cloudformation describe-stacks --stack-name sasha \
| jq -r '.Stacks[].Outputs[] | select(.OutputKey == "VlrMatchesTableName" ) | .OutputValue'`
echo "SASHA_TABLE_NAME=$SASHA_TABLE_NAME" >> $GITHUB_ENV
echo "SASHA_TABLE_NAME=$SASHA_TABLE_NAME" >> $GITHUB_ENV
- name: Prepare SAM parameters
env:
SAM_DEPLOY_STAGE: ${{ vars.SAM_DEPLOY_STAGE }}
APPLICATION_NAME: ${{ env.APPLICATION_NAME }}
SASHA_TABLE_NAME: ${{ env.SASHA_TABLE_NAME }}
API_DOMAIN_NAME: ${{ secrets.API_DOMAIN_NAME }}
CERTIFICATE_ARN: ${{ secrets.CERTIFICATE_ARN }}
Expand All @@ -47,7 +51,7 @@ jobs:
run: |
tee params.json << EOF
{
"SAMDeployStage": "${SAM_DEPLOY_STAGE}",
"ApplicationName": "${APPLICATION_NAME}",
"SashaTableName": "${SASHA_TABLE_NAME}",
"APIDomainName": "${API_DOMAIN_NAME}",
"CertificateArn": "${CERTIFICATE_ARN}",
Expand All @@ -56,7 +60,7 @@ jobs:
}
EOF
- name: Build SAM packages
run: sam build --use-container
run: sam build
- name: Deploy SAM application
env:
BUCKET_NAME: ${{ secrets.PROVISIONING_BUCKET_NAME }}
Expand Down
148 changes: 21 additions & 127 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,138 +1,32 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints
# Test binary, built with `go test -c`
*.test

# IPython
profile_default/
ipython_config.py
# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# pyenv
.python-version
# Dependency directories (remove the comment below to include it)
# vendor/

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# Go workspace file
go.work
go.work.sum

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
# env file
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# aws-chalice
api/.chalice/deployed
api/.chalice/deployments
api/.chalice/config.json

# aws-sam
.aws-sam
samconfig.toml

# Local binary file
dima
6 changes: 0 additions & 6 deletions .vscode/settings.json

This file was deleted.

18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.DEFAULT_GOAL := build

fmt:
go fmt
.PHONY: fmt

lint: fmt
staticcheck
.PHONY: lint

vet: lint
go vet
.PHONY: vet

build: vet
go mod tidy
CGO_ENABLED=0 go build
.PHONY: build
17 changes: 0 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,6 @@ $ curl endpoint/api/matches?date=2023-05-28

## usage

### for quick trial

- In advance, You may have to deploy [sasha](https://github.com/miztch/sasha), data source of dima.
- You can deploy with [AWS Chalice](https://github.com/aws/chalice)

```bash
table=YOUR_SASHA_TABLE_NAME
sed -i -e 's/SASHA_DYNAMODB_TABLE_NAME/$table/g' api/.chalice/config_template.json
mv api/.chalice/config_template.json api/.chalice/config.json

cd api
chalice deploy
curl http://${your-api-endpoint}/api/
```

### for permanent deployment

- You can use AWS SAM template (`template.yaml`)
- Custom domain with ACM / Route53 Hostzone is implemented. Please remove it if you don't need.

Expand Down
13 changes: 0 additions & 13 deletions api/.chalice/config_template.json

This file was deleted.

39 changes: 0 additions & 39 deletions api/app.py

This file was deleted.

Empty file removed api/chalicelib/__init__.py
Empty file.
Loading

0 comments on commit 944b2fa

Please sign in to comment.