Skip to content

Commit

Permalink
Merge pull request #2 from NBISweden/push-static-files
Browse files Browse the repository at this point in the history
Push static files
  • Loading branch information
darthvader2 authored Feb 29, 2024
2 parents bb1e95c + 381ad1b commit b8e396c
Show file tree
Hide file tree
Showing 44 changed files with 6,463 additions and 14 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web/content/datasets/*
25 changes: 25 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Push
on:
push:
branches:
- master

jobs:
publish-image:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: true
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
web/*
web/public/
dev_utils/config.yaml
web/static/img/m_p_b/
web/static/img/m_p_c/
web/static/img/m_p_p/
web/static/img/m_r_f/
web/content/datasets/*
16 changes: 8 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
FROM golang:1.20.3-alpine3.17 as build

WORKDIR /lp_app
COPY . .
ENV GO111MODULE=on
ENV GOPATH=$PWD
ENV GOOS=linux
RUN go build -o /test .

ENV CGO_ENABLED=0
RUN go build -o test .

FROM alpine:3.17

WORKDIR /gen_app
RUN apk add --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community hugo
COPY --from=build /test /gen_app/
RUN apk add --no-cache --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community hugo
COPY --from=build /lp_app/test /gen_app
COPY dev_utils .
CMD ["/gen_app/test"]
COPY /web /web

CMD ["./test"]
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
# bp-landing-pages
# Bigpicture-landing-pages-service
Bigpicture project dataset landing page generator


## Development environment

To start S3 minio service, navigate to dev_utils folder and run

```
docker compose up
```

Set config.yaml in environment file

```
export CONFIGFILE="dev_utils/config.yaml"
```

Start the application by running
```
go run .
```
44 changes: 43 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ import (
"github.com/spf13/viper"
)

func getConfig() MetadataS3Config {
func getMetadataConfig() MetadataS3Config {
parseConfig()
S3Conf := configS3Storage()
return S3Conf
}

func getDeploymentConfig() DeployS3Config {
parseConfig()
dS3Conf := deployS3Storage()
return dS3Conf
}

type MetadataS3Config struct {
Expand All @@ -26,6 +31,17 @@ type MetadataS3Config struct {
WebMetadataFolder string
}

type DeployS3Config struct {
URL string
Port int
AccessKey string
SecretKey string
Bucket string
Region string
Chunksize int
Cacert string
}

func configS3Storage() MetadataS3Config {
s3 := MetadataS3Config{}
s3.URL = viper.GetString("S3MetadataBucket.url")
Expand Down Expand Up @@ -53,6 +69,32 @@ func configS3Storage() MetadataS3Config {
return s3
}

func deployS3Storage() DeployS3Config {
s3 := DeployS3Config{}
s3.URL = viper.GetString("S3DeploymentBucket.url")
s3.AccessKey = viper.GetString("S3DeploymentBucket.accesskey")
s3.SecretKey = viper.GetString("S3DeploymentBucket.secretkey")
s3.Bucket = viper.GetString("S3DeploymentBucket.bucket")
s3.Port = 9000
if viper.IsSet("s3.port") {
s3.Port = viper.GetInt("S3DeploymentBucket.port")
}

if viper.IsSet("s3.region") {
s3.Region = viper.GetString("S3DeploymentBucket.region")
}

if viper.IsSet("s3.chunksize") {
s3.Chunksize = viper.GetInt("S3DeploymentBucket.chunksize") * 1024 * 1024
}

if viper.IsSet("s3.cacert") {
s3.Cacert = viper.GetString("S3DeploymentBucket.cacert")
}

return s3
}

func parseConfig() {
viper.SetConfigName("config")
viper.AddConfigPath(".")
Expand Down
6 changes: 6 additions & 0 deletions dev_utils/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@ S3MetadataBucket:
bucket: "test/"
WebMetadataFolder: "web/content/"

S3DeploymentBucket:
url: "http://127.0.0.1:9000"
accesskey: "myaccesskey"
secretkey: "mysecretkey"
region: "us-east-1"
bucket: "deply/"

13 changes: 11 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
package main

import (
"os/exec"

log "github.com/sirupsen/logrus"
)

func main() {
log.Infoln("started app successfully")
mConf := getConfig()
Metadataclient := connect_to_s3(mConf)
mConf := getMetadataConfig()
Metadataclient := connectMetadatas3(mConf)
log.Infof("Connection to the bucket established")
metadataDownloader(Metadataclient)
cmd := exec.Command("hugo")
cmd.Dir = "./web/"
cmd.Run()

Check failure on line 17 in main.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `cmd.Run` is not checked (errcheck)
log.Infof("Hugo successfully built")
deConf := getDeploymentConfig()
connectDeployments3(deConf)

}
44 changes: 43 additions & 1 deletion s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ type MetadataBackend struct {
Client *s3.Client
Bucket string
}
type DeploymentBackend struct {
Client *s3.Client
Bucket string
}

func connect_to_s3(mConf MetadataS3Config) *MetadataBackend {
func connectMetadatas3(mConf MetadataS3Config) *MetadataBackend {
httpClient := awshttp.NewBuildableClient().WithTransportOptions(func(tr *http.Transport) {
if tr.TLSClientConfig == nil {
tr.TLSClientConfig = &tls.Config{}
Expand Down Expand Up @@ -55,3 +59,41 @@ func connect_to_s3(mConf MetadataS3Config) *MetadataBackend {
}
return metadata_client
}

func connectDeployments3(dConf DeployS3Config) *DeploymentBackend {
httpClient := awshttp.NewBuildableClient().WithTransportOptions(func(tr *http.Transport) {
if tr.TLSClientConfig == nil {
tr.TLSClientConfig = &tls.Config{}
}
tr.TLSClientConfig.MinVersion = tls.VersionTLS13
})

cfg, err := config.LoadDefaultConfig(context.TODO(),
config.WithRegion(dConf.Region),
config.WithHTTPClient(httpClient),
config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(dConf.AccessKey, dConf.SecretKey, "")),
config.WithEndpointResolverWithOptions(aws.EndpointResolverWithOptionsFunc(
func(service, region string, options ...interface{}) (aws.Endpoint, error) {
return aws.Endpoint{URL: dConf.URL}, nil
})),
)

if err != nil {
log.Fatalf("Error while setting up s3 config: %v\n ", err)
}
client := s3.NewFromConfig(cfg)
deployment_client := &DeploymentBackend{

Client: client,
Bucket: dConf.Bucket,
}
_, err = deployment_client.Client.ListObjectsV2(context.TODO(), &s3.ListObjectsV2Input{
Bucket: aws.String(deployment_client.Bucket),
})
if err != nil {
log.Fatalf("Error while connecting to the deplpyment bucket %v\n ", err)
} else {
log.Infoln("Connection established to deployment bucket", deployment_client.Bucket)
}
return deployment_client
}
Empty file added web/.hugo_build.lock
Empty file.
10 changes: 10 additions & 0 deletions web/archetypes/dataset.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: "An Example Post"
subtitle: ""
description: ""
date: 2018-06-04
author:     ""
image: ""
tags: ["tag1", "tag2"]
categories: ["Tech" ]
---
6 changes: 6 additions & 0 deletions web/archetypes/default.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: "{{ replace .Name "-" " " | title }}"
date: {{ .Date }}
draft: true
---

20 changes: 20 additions & 0 deletions web/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
baseurl = "https://nbisweden.github.io/hugo.bp.datasets.nbis.se"
title = "Bigpicture datasets"
languageCode = "en-us"
preserveTaxonomyNames = true
paginate = 5 #frontpage pagination


[params]
header_image = "img/bigpicture-banner.jpg"
SEOTitle = "Bigpicture datasets"
slogan = "Demo site for Bigpicture landing pages using HUGO"

image_404 = "img/404-bg.jpg"

# Sidebar settings
sidebar_about_description = "Bigpicture dataset description pages"
sidebar_avatar = "img/bigpicture_logo.svg" # use absolute URL, seeing it's used in both `/` and `/about/`


[[params.addtional_menus]]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit b8e396c

Please sign in to comment.