-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add terraform infra as code and docker build GHA
- Loading branch information
Showing
13 changed files
with
165 additions
and
4 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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
name: Docker Build | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
tags: [ '*.*.*' ] | ||
|
||
env: | ||
GCP_PROJECT: ${{ secrets.GCP_PROJECT }} | ||
GCP_IMAGE: ${{ secrets.GCP_IMAGE }} | ||
|
||
jobs: | ||
docker: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Prepare | ||
id: prep | ||
run: | | ||
DOCKER_IMAGE=gcr.io/${GCP_PROJECT}/${GCP_IMAGE} | ||
VERSION=$(echo $GITHUB_REF | sed 's/refs\/tags\///') | ||
DOCKER_TAG=${DOCKER_IMAGE}:${VERSION} | ||
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then | ||
MINOR=${VERSION%.*} | ||
MAJOR=${MINOR%.*} | ||
TAGS="$TAGS,${DOCKER_IMAGE}:${MINOR},${DOCKER_IMAGE}:${MAJOR},${DOCKER_IMAGE}:latest" | ||
elif [ "${{ github.event_name }}" = "push" ]; then | ||
TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}" | ||
fi | ||
echo ::set-output name=version::${VERSION} | ||
echo ::set-output name=tags::${TAGS} | ||
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ') | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v1 | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
- name: Login to GCR | ||
if: github.event_name != 'pull_request' | ||
uses: docker/login-action@v1 | ||
with: | ||
registry: gcr.io | ||
username: _json_key | ||
password: ${{ secrets.GCR_JSON_KEY }} | ||
- name: Build and push | ||
id: docker_build | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: . | ||
file: ./Dockerfile | ||
platforms: linux/amd64 | ||
push: ${{ github.event_name != 'pull_request' }} | ||
tags: ${{ steps.prep.outputs.tags }} | ||
labels: | | ||
org.opencontainers.image.title=${{ github.event.repository.name }} | ||
org.opencontainers.image.description=${{ github.event.repository.description }} | ||
org.opencontainers.image.url=${{ github.event.repository.html_url }} | ||
org.opencontainers.image.source=${{ github.event.repository.clone_url }} | ||
org.opencontainers.image.version=${{ steps.prep.outputs.version }} | ||
org.opencontainers.image.created=${{ steps.prep.outputs.created }} | ||
org.opencontainers.image.revision=${{ github.sha }} | ||
org.opencontainers.image.licenses=${{ github.event.repository.license.spdx_id }} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
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,3 @@ | ||
* | ||
!.gitignore | ||
!README.md |
Empty file.
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,63 @@ | ||
resource "google_project_service" "run" { | ||
service = "run.googleapis.com" | ||
} | ||
|
||
resource "google_cloud_run_service" "rshinycloudrun" { | ||
name = "rshinycloudrun" | ||
location = var.region | ||
project = var.project | ||
|
||
template { | ||
spec { | ||
containers { | ||
image = "gcr.io/rshinycloudrun/rshinycloudrun" | ||
resources { | ||
limits { | ||
cpu = "1000m" | ||
memory = "1024Mi" | ||
} | ||
requests { | ||
cpu = "500m" | ||
memory = "500Mi" | ||
} | ||
} | ||
ports { | ||
container_port = 5000 | ||
} | ||
} | ||
|
||
container_concurrency = 80 | ||
timeout_seconds = 300 | ||
} | ||
metadata { | ||
annotations = { | ||
"autoscaling.knative.dev/minScale" = 0 | ||
"autoscaling.knative.dev/maxScale" = 10 | ||
} | ||
} | ||
} | ||
|
||
traffic { | ||
percent = 100 | ||
latest_revision = true | ||
} | ||
|
||
depends_on = [google_project_service.run] | ||
} | ||
|
||
resource "google_cloud_run_service_iam_member" "allUsers" { | ||
service = google_cloud_run_service.rshinycloudrun.name | ||
location = var.region | ||
project = var.project | ||
role = "roles/run.invoker" | ||
member = "allUsers" | ||
} | ||
|
||
resource "google_cloud_run_domain_mapping" "rshinycloudrun" { | ||
name = "rshinycloudrun" | ||
location = var.region | ||
project = var.project | ||
spec { | ||
route_name = google_cloud_run_service.rshinycloudrun.name | ||
} | ||
} |
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,3 @@ | ||
output "url" { | ||
value = google_cloud_run_service.rshinycloudrun.status[0].url | ||
} |
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,14 @@ | ||
terraform { | ||
required_providers { | ||
google = { | ||
source = "hashicorp/google" | ||
version = ">= 3.56" | ||
} | ||
} | ||
} | ||
|
||
provider "google" { | ||
credentials = file(var.credentials_file) | ||
project = var.project | ||
region = var.region | ||
} |
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 @@ | ||
variable project { | ||
type = string | ||
default = "" | ||
description = "Google Cloud Project ID" | ||
} | ||
|
||
variable region { | ||
type = string | ||
default = "us-east1" | ||
description = "Google Cloud Region" | ||
} | ||
|
||
variable credentials_file { | ||
type = string | ||
default = "" | ||
description = "Path to Google Cloud credentials file" | ||
} |
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,3 @@ | ||
terraform { | ||
required_version = ">= 0.13" | ||
} |