2

I was able to build both the JavaScript bundle, and the Go binary. But, I'm currently unable, due to lack of knowledge, to make the Go server run for the backend, and to display the public/index.html as the entry for the front-end.

How could I accomplish that, adding to the existing yaml file?

The repository: https://github.com/BuddhiLW/free-riding. The yaml file: https://github.com/BuddhiLW/free-riding/blob/main/.github/workflows/deploy.yaml

Current state of the Yaml file:

# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the "main" branch
  push:
    branches: ["main"]
  pull_request:
    branches: ["main"]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v3

      - name: Set Node.js 16.x
        uses: actions/setup-node@v3
        with:
          node-version: 16.x

      - name: Run install
        uses: borales/actions-yarn@v4
        with:
          cmd: install # will run `yarn install` command

      - name: Install Lynx
        uses: awalsh128/cache-apt-pkgs-action@latest
        with:
          packages: lynx
          version: 1.0

      - name: Prepare java
        uses: actions/setup-java@v3
        with:
          distribution: "zulu"
          java-version: "17"

      - name: Install clojure tools
        uses: DeLaGuardo/[email protected]
        with:
          # Install just one or all simultaneously
          # The value must indicate a particular version of the tool, or use 'latest'
          # to always provision the latest version
          cli: latest # Clojure CLI based on tools.deps

      - name: Generate js bundle
        uses: borales/actions-yarn@v4
        with:
          cmd: run build

  golang-server:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        go: ["1.20.3"]
    name: Go ${{ matrix.go }} sample
    steps:
      - uses: actions/checkout@v3
      - name: Setup go
        uses: actions/setup-go@v4
        with:
          go-version: ${{ matrix.go }}
      - run: |
          go build

Current status of the build process: enter image description here

1 Answer 1

1

Where are you trying to deploy the software to? You cannot run a go server in a pipeline to serve a website for production purposes (for one, after an hour it's gone). Since you seem to use go only to run a server, I would maybe try to deploy somewhere else? For example, Google Firebase (to serve static files, like the compiled cljs)?

For Firebase looks like this:

Make an account add https://firebase.google.com/ and a project + token.

firebase.json

{
  "hosting": {
    "public": "resources/public",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

Run npm i firebase to install firebase in package.json.

Add an action to deploy to Firebase on pushes to main/master:

name: Deploy to Firebase Hosting on push to master
on:
  push:
    branches: [master]
jobs:
  test_build_and_deploy:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Test
      run: make test
    - name: Build
      run: make prod
    - name: Deploy
      uses: w9jds/firebase-action@master
      with:
        args: deploy --only hosting
      env:
        FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}

Add FIREBASE_TOKEN in a GitHub secret.

For serving static files somewhere else than Firebase I would advise using the web server NGINX. Make an NGINX Docker container and host that container somewhere (e.g. a cloud provider). Dockerfile will look something like this:

FROM nginxinc/nginx-unprivileged:1.23
COPY resources/public /usr/share/nginx/html
COPY nginx/default.template /etc/nginx/conf.d/default.conf
CMD nginx -g 'daemon off;'

default.conf:

server {
    listen 8080;
    root /usr/share/nginx/html;
    index index.html index.htm;
    location / {
        try_files $uri /index.html;
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.