Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
6075547
Docker stuff
TyHil Feb 19, 2025
355aad7
GitHub Action
TyHil Feb 19, 2025
dc2fc2c
Quotes
TyHil Feb 19, 2025
086d3f3
is the secret there?
TyHil Feb 19, 2025
d36acca
deployment env
TyHil Feb 19, 2025
02ce429
Revert "is the secret there?"
TyHil Feb 19, 2025
5e365cb
use federated thing
TyHil Feb 20, 2025
6414a25
permissions
TyHil Feb 20, 2025
ee7911b
provider
TyHil Feb 20, 2025
12cfd92
github/actions-oidc-debugger
TyHil Feb 20, 2025
e9e4b90
Revert "github/actions-oidc-debugger"
TyHil Feb 20, 2025
5d2b0c2
Use gcloud CLI
TyHil Feb 20, 2025
17e4aaa
build-push-action
TyHil Feb 20, 2025
4d040bc
docker/login-action@
TyHil Feb 20, 2025
f9c1369
id auth
TyHil Feb 20, 2025
ff833fa
token_format: access_token
TyHil Feb 20, 2025
623bbba
google-github-actions/deploy-cloudrun
TyHil Feb 20, 2025
2ed7fe7
service -> job
TyHil Feb 20, 2025
62e1379
bump versions
TyHil Feb 20, 2025
442c4c9
region
TyHil Feb 20, 2025
82dc56b
scrape mazevo too
TyHil Feb 20, 2025
65a85db
only on develop
TyHil Feb 20, 2025
eab3852
Revert "only on develop"
TyHil Feb 20, 2025
7c59bfb
big region change
TyHil Feb 20, 2025
1c521cc
remove exec
TyHil Feb 20, 2025
aa4309d
Reapply "only on develop"
TyHil Feb 20, 2025
de1d9e5
mazevo indentation
TyHil Feb 20, 2025
4616906
print when done in mazevo and astra scrapers for logs
TyHil Feb 20, 2025
eae0456
detect empty env values
TyHil Feb 20, 2025
701900e
Use a service account to auth the env
TyHil Feb 20, 2025
6ca207e
Revert "Reapply "only on develop""
TyHil Feb 20, 2025
6bce8da
Reapply "Reapply "only on develop""
TyHil Feb 20, 2025
9f69d59
Merge branch 'develop' into deployment-google
TyHil Feb 20, 2025
d6d8afb
Merge branch 'develop' into deployment-google
jpahm Feb 22, 2025
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
55 changes: 55 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# This workflow deploys the repository to run daily on google cloud run

name: Deploy

on:
push:
branches: develop

jobs:
main:
runs-on: ubuntu-latest
environment: deployment

permissions:
contents: 'read'
id-token: 'write'

steps:
- id: auth
name: Google Cloud Auth
uses: google-github-actions/auth@v2
with:
token_format: access_token
workload_identity_provider: projects/762526944259/locations/global/workloadIdentityPools/pool/providers/github-deploy
service_account: '[email protected]'

- name: Set up Google Cloud
uses: google-github-actions/setup-gcloud@v2

- name: Login to Artifact Registry
uses: docker/login-action@v3
with:
registry: us-central1-docker.pkg.dev
username: oauth2accesstoken
password: ${{ steps.auth.outputs.access_token }}

- name: Build Docker image
uses: docker/build-push-action@v6
with:
push: true
tags: us-central1-docker.pkg.dev/api-tools-451421/runners/daily-update-events

- name: Upload to dev job
uses: google-github-actions/deploy-cloudrun@v2
with:
job: 'daily-update-events-dev'
image: 'us-central1-docker.pkg.dev/api-tools-451421/runners/daily-update-events'
region: us-central1

- name: Upload to prod job
uses: google-github-actions/deploy-cloudrun@v2
with:
job: 'daily-update-events-prod'
image: 'us-central1-docker.pkg.dev/api-tools-451421/runners/daily-update-events'
region: us-central1
8 changes: 4 additions & 4 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ name: Go

on:
push:
branches: [ "develop" ]
branches: develop
pull_request:
branches: [ "develop" ]
branches: develop
workflow_dispatch:

jobs:
Expand All @@ -17,10 +17,10 @@ jobs:
steps:

- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: '1.23'

Expand Down
31 changes: 31 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM golang:1.23 AS builder

WORKDIR /app
COPY . .

# Run setup and checks
RUN make setup
RUN make check
RUN make build

# Use a lightweight final image
FROM debian:12-slim
WORKDIR /app

# Install gcloud CLI
RUN apt-get update && apt-get install -y wget gnupg apt-transport-https lsb-release ca-certificates
RUN wget -qO - https://packages.cloud.google.com/apt/doc/apt-key.gpg | gpg --dearmor > /usr/share/keyrings/cloud.google.gpg
RUN echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
RUN apt-get update && apt-get install -y google-cloud-sdk

# Install chromium
RUN apt-get update && apt-get install -y chromium
ENV CHROMIUM_BIN /usr/bin/chromium
ENV GOOGLE_CHROME_BIN /usr/bin/chromium # Also set this for compatibility

# Copy build file from builder
COPY --from=builder /app/api-tools /app/api-tools
COPY deploy.sh /app/deploy.sh

RUN chmod +x /app/deploy.sh
ENTRYPOINT ["/app/deploy.sh"]
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ check:
go mod tidy
go vet ./...
staticcheck ./...
gofmt -w ./..
goimports -w ./..
gofmt -w .
goimports -w .

build: ./main.go
go build -o $(EXEC_NAME) ./main.go
Expand Down
16 changes: 16 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh

# service account
gcloud secrets versions access latest --secret="$SERVICE_ACCOUNT_SECRET_NAME" > service_account.json
gcloud auth activate-service-account --key-file=service_account.json
rm service_account.json

# .env
gcloud secrets versions access latest --secret="$ENV_SECRET_NAME" > .env

# Scrape, parse, and upload
./api-tools -scrape -mazevo -verbose
#./api-tools -parse -mazevo -verbose
./api-tools -scrape -astra -verbose
#./api-tools -parse -astra -verbose
#./api-tools -upload -events -verbose
2 changes: 2 additions & 0 deletions scrapers/astra.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ func ScrapeAstra(outDir string) {
date = date.Add(time.Hour * 24)
}

log.Printf("Scraped Astra up to %s!", date.Format("2006-01-02"))

// Write event data to output file
days = fmt.Sprintf("%s}", days)
fptr, err := os.Create(fmt.Sprintf("%s/reservations.json", outDir))
Expand Down
61 changes: 30 additions & 31 deletions scrapers/mazevo.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,38 +43,37 @@ func ScrapeMazevo(outDir string) {
endDate := date.Add(time.Hour * 24 * 365).Format(time.RFC3339)

// Request events
stringBody := ""
{
url := "https://east.mymazevo.com/api/PublicCalendar/GetCalendarEvents"
requestBodyMap := map[string]string{
"apiKey": apikey,
"end": endDate,
"start": startDate,
}
requestBodyBytes, _ := json.Marshal(requestBodyMap)
requestBody := bytes.NewBuffer(requestBodyBytes)
req, err := http.NewRequest("POST", url, requestBody)
if err != nil {
panic(err)
}
req.Header = http.Header{
"Content-type": {"application/json"},
"Accept": {"application/json"},
}
res, err := cli.Do(req)
if err != nil {
panic(err)
}
if res.StatusCode != 200 {
log.Panicf("ERROR: Status was: %s\nIf the status is 404, you've likely been IP ratelimited!", res.Status)
}
body, err := io.ReadAll(res.Body)
if err != nil {
panic(err)
}
res.Body.Close()
stringBody = string(body)
url := "https://east.mymazevo.com/api/PublicCalendar/GetCalendarEvents"
requestBodyMap := map[string]string{
"apiKey": apikey,
"end": endDate,
"start": startDate,
}
requestBodyBytes, _ := json.Marshal(requestBodyMap)
requestBody := bytes.NewBuffer(requestBodyBytes)
req, err := http.NewRequest("POST", url, requestBody)
if err != nil {
panic(err)
}
req.Header = http.Header{
"Content-type": {"application/json"},
"Accept": {"application/json"},
}
res, err := cli.Do(req)
if err != nil {
panic(err)
}
if res.StatusCode != 200 {
log.Panicf("ERROR: Status was: %s\nIf the status is 404, you've likely been IP ratelimited!", res.Status)
}
body, err := io.ReadAll(res.Body)
if err != nil {
panic(err)
}
res.Body.Close()
stringBody := string(body)

log.Printf("Scraped Mazevo up to %s!", endDate)

// Write event data to output file
fptr, err := os.Create(fmt.Sprintf("%s/mazevoReservations.json", outDir))
Expand Down
4 changes: 2 additions & 2 deletions utils/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var Headless = true
// Finds .env value and produces proper error if not found
func GetEnv(name string) (string, error) {
value, exists := os.LookupEnv(name)
if !exists {
if !exists || value == "" {
return "", errors.New(name + " is missing from .env!")
}
return value, nil
Expand Down Expand Up @@ -152,7 +152,7 @@ func RefreshAstraToken(chromedpCtx context.Context) map[string][]string {
for _, cookie := range cookies {
cookieStr = fmt.Sprintf("%s%s=%s; ", cookieStr, cookie.Name, cookie.Value)
if cookie.Name == "UTXDallas.ASPXFORMSAUTH" {
VPrintf("Got new token: PTGSESSID = %s", cookie.Value)
VPrintf("Got new token: UTXDallas.ASPXFORMSAUTH = %s", cookie.Value)
gotToken = true
}
}
Expand Down
Loading