-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reorganize rest_server template with new layout and subfolder convent…
…ion (#180) Addresses #173, also reformats subdirectory contents in accordance to #166. Template structure: ``` $ tree -all . ├── contents │ ├── go.mod │ ├── go.sum │ ├── main.go │ ├── main_test.go │ └── README.md ├── deployments │ ├── config │ │ └── autopush-rest-server.env │ ├── contents │ │ └── Dockerfile │ ├── README.md │ ├── spec.yaml │ └── workflows │ ├── ci-rest-server.yaml │ └── deploy-rest-server.yaml ├── README.md └── spec.yaml ``` Rendered template structure: ``` $ tree -all . ├── Dockerfile ├── .github │ ├── config │ │ └── autopush-rest-server.env │ └── workflows │ ├── ci-rest-server.yaml │ └── deploy-rest-server.yaml ├── go.mod ├── go.sum ├── main.go ├── main_test.go └── README.md ```
- Loading branch information
1 parent
de35382
commit c4d5678
Showing
13 changed files
with
112 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,16 @@ | ||
# Example: REST server | ||
# Template: REST server | ||
|
||
Simple HTTP/JSON REST server implemented in Go, using go-chi for HTTP routing. | ||
Template for a simple HTTP/JSON REST server implemented in Go, using go-chi for HTTP routing. | ||
|
||
To run this, cd to the root of this git repo, then run these steps: | ||
How to render this template: | ||
|
||
1. cd into an empty directory | ||
1. [Install the abc binary](https://github.com/abcxyz/abc#installation). | ||
|
||
```shell | ||
$ mkdir ~/template_tmp | ||
$ cd ~/template_tmp | ||
``` | ||
|
||
1. Install the `abc` binary | ||
|
||
```shell | ||
$ go install github.com/abcxyz/abc/cmd/abc@latest | ||
$ abc --help | ||
``` | ||
|
||
This only works if you have go installed (https://go.dev/doc/install) and have the Go binary directory in your $PATH (try PATH=$PATH:~/go/bin). | ||
|
||
1. Execute the template defined in the `t` directory. | ||
This will output a file named `main.go` in your working directory containing | ||
the transformed program. | ||
1. Render via: | ||
|
||
```shell | ||
$ abc templates render github.com/abcxyz/abc.git//t/rest_server | ||
``` | ||
|
||
1. Run the transformed program: | ||
|
||
```shell | ||
$ go run . | ||
[yyyy/mm/dd hh:mm:ss] starting server on 8080 | ||
``` | ||
1. Follow the steps in the rendered README.md to run the server. | ||
|
||
1. In a separate shell, run: | ||
|
||
```shell | ||
$ curl localhost:8080 | ||
{"message":"hello world"} | ||
``` | ||
1. Optionally, render the CI/CD workflows as well (see subfolder README for more details). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Simple REST server | ||
|
||
This is a simple HTTP/JSON REST server implemented in Go, using go-chi for HTTP routing. | ||
|
||
How to run this server: | ||
|
||
1. Run the server: | ||
|
||
```shell | ||
$ go run . | ||
[yyyy/mm/dd hh:mm:ss] starting server on 8080 | ||
``` | ||
1. In a separate shell, run: | ||
```shell | ||
$ curl localhost:8080 | ||
{"message":"hello world"} | ||
``` |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# REST server workflows template | ||
|
||
This directory contains the CI/CD GitHub Action workflows for the REST server template. | ||
|
||
$ abc templates render -input="automation_service_account=[automation_service_account]" \ | ||
-input="wif_provider=[wif_provider]" \ | ||
-input="ar_repository=[ar_repository]" \ | ||
-input="ar_location=[ar_location]" \ | ||
-input="cr_service=[cr_service]" \ | ||
-input="region=[region]" \ | ||
-input="project_id=[project_id]" \ | ||
github.com/abcxyz/abc.git//t/rest_server/workflows |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Copyright 2023 The Authors (see AUTHORS file) | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
apiVersion: 'cli.abcxyz.dev/v1alpha1' | ||
kind: 'Template' | ||
desc: 'REST server workflows template' | ||
inputs: | ||
- name: 'automation_service_account' | ||
desc: | ||
'Automation Service Account (ex: | ||
[account_name]@[project_id].iam.gserviceaccount.com)' | ||
rules: | ||
- rule: 'gcp_matches_service_account(automation_service_account)' | ||
message: 'Service account should match format: | ||
[account_name]@[project_id].iam.gserviceaccount.com)' | ||
- name: 'wif_provider' | ||
desc: | ||
'Workload Identity Federation Provider (ex: | ||
projects/[project_id]/locations/global/workloadIdentityPools/[WIF_pool_name]/providers/[provider_name])' | ||
- name: 'ar_repository' | ||
desc: 'Artifact Registry Repository (ex: ci-images)' | ||
- name: 'ar_location' | ||
desc: 'Artifact Registry Location (ex: us-docker.pkg.dev)' | ||
- name: 'cr_service' | ||
desc: 'Cloud Run Service (ex: hello-jupiter-api)' | ||
- name: 'region' | ||
desc: 'Cloud Run Region (ex: us-west1)' | ||
- name: 'project_id' | ||
desc: 'GCP Project ID' | ||
rules: | ||
- rule: 'gcp_matches_project_id(project_id)' | ||
message: 'Must be a GCP project ID' | ||
steps: | ||
- desc: 'Include workflow, deployment files' | ||
action: 'include' | ||
params: | ||
paths: ['workflows', 'config', 'contents'] | ||
as: ['.github/workflows', '.github/config', '.'] | ||
- desc: 'Replace sentinel values with real input values' | ||
action: 'string_replace' | ||
params: | ||
paths: ['.'] | ||
replacements: | ||
- to_replace: 'AUTOMATION_SERVICE_ACCOUNT=[automation_service_account]' | ||
with: 'AUTOMATION_SERVICE_ACCOUNT={{.automation_service_account}}' | ||
- to_replace: 'WIF_PROVIDER=[wif_provider]' | ||
with: 'WIF_PROVIDER={{.wif_provider}}' | ||
- to_replace: 'AR_REPOSITORY=[ar_repository]' | ||
with: 'AR_REPOSITORY={{.ar_repository}}' | ||
- to_replace: 'AR_LOCATION=[ar_location]' | ||
with: 'AR_LOCATION={{.ar_location}}' | ||
- to_replace: 'CR_SERVICE=[cr_service]' | ||
with: 'CR_SERVICE={{.cr_service}}' | ||
- to_replace: 'REGION=[region]' | ||
with: 'REGION={{.region}}' | ||
- to_replace: 'PROJECT_ID=[project_id]' | ||
with: 'PROJECT_ID={{.project_id}}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters