Skip to content

Commit e96a803

Browse files
committed
add a docker image
1 parent 83cd674 commit e96a803

File tree

5 files changed

+68
-24
lines changed

5 files changed

+68
-24
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ name: Build Depositor
55

66
on:
77
push:
8-
branches:
9-
- main
10-
- *-release
8+
branches: [ "main" ]
119
pull_request:
1210
branches: [ "main" ]
1311

@@ -19,7 +17,7 @@ jobs:
1917
- uses: actions/[email protected]
2018
- uses: actions/setup-go@v2
2119
with:
22-
go-version: '1.21'
20+
go-version: '1.22.6'
2321
- name: generate
2422
run: go generate ./...
2523
- name: golangci-lint
@@ -40,5 +38,6 @@ jobs:
4038
- name: Build
4139
run: go build -v ./...
4240

41+
# need to add tests
4342
- name: Test
4443
run: go test -v ./...

.github/workflows/release.yaml

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ on:
55
tags:
66
- "v*"
77

8-
permissions:
9-
contents: write
8+
env:
9+
REGISTRY: ghcr.io
10+
IMAGE_NAME: ${{ github.repository }}
1011

1112
jobs:
1213
goreleaser:
1314
runs-on: ubuntu-latest
15+
permissions:
16+
contents: write
1417
steps:
1518
- name: Checkout
1619
uses: actions/checkout@v4
@@ -28,4 +31,45 @@ jobs:
2831
version: latest
2932
args: release --clean
3033
env:
31-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35+
build-and-push-docker-image:
36+
runs-on: ubuntu-latest
37+
permissions:
38+
contents: read
39+
packages: write
40+
attestations: write
41+
id-token: write
42+
steps:
43+
- name: Checkout repository
44+
uses: actions/checkout@v4
45+
46+
- name: Log in to the Container registry
47+
uses: docker/login-action@v3
48+
with:
49+
registry: ${{ env.REGISTRY }}
50+
username: ${{ github.actor }}
51+
password: ${{ secrets.GITHUB_TOKEN }}
52+
53+
- name: Extract metadata (tags, labels) for Docker
54+
id: meta
55+
uses: docker/metadata-action@v5
56+
with:
57+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
58+
- name: Build and push Docker image
59+
id: push
60+
uses: docker/build-push-action@v6
61+
with:
62+
context: .
63+
push: true
64+
platforms: linux/amd64,linux/arm64
65+
build-args: |
66+
VERSION=${{ steps.meta.outputs.tags }}
67+
tags: ${{ steps.meta.outputs.tags }}
68+
labels: ${{ steps.meta.outputs.labels }}
69+
- name: Generate artifact attestation
70+
uses: actions/attest-build-provenance@v2
71+
with:
72+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
73+
subject-digest: ${{ steps.push.outputs.digest }}
74+
push-to-registry: true
75+

Dockerfile

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,32 @@ COPY go.mod go.sum ./
1111
RUN go mod download
1212

1313
# Copy the source code
14-
COPY ./depositions/onedep ./depositions/onedep
15-
COPY ./conversions.csv /app/conversions.csv
14+
COPY main.go ./
15+
COPY conversions.csv /app/conversions.csv
16+
COPY mmcif_pdbx_v50.dic /app/mmcif_pdbx_v50.dic
17+
COPY depositions/onedep ./depositions/onedep
18+
COPY docs ./docs
1619

17-
# Build
18-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go generate ./depositions/onedep
19-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /app/depositor ./depositions/onedep
20+
ARG VERSION=v.0.1.0
21+
22+
# Build GOARCH=amd64
23+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} go generate .
24+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} go build -o /app/depositor
2025

2126
# Final stage
2227
FROM alpine:latest
2328

24-
# Install necessary packages
25-
RUN apk add --no-cache ca-certificates
26-
2729
# Set environment variables
28-
ENV PORT=8080
30+
ENV PORT=8888
2931
ENV ALLOW_ORIGINS=http://localhost:4200
3032

31-
# Copy the binary from the builder stage
33+
# Copy the binary and other necessary files from the builder stage
3234
COPY --from=builder /app/depositor /app/depositor
3335
COPY --from=builder /app/conversions.csv /app/conversions.csv
36+
COPY --from=builder /app/mmcif_pdbx_v50.dic /app/mmcif_pdbx_v50.dic
3437

35-
# Set executable permission for the depositor binary
36-
RUN chmod +x /app/depositor
3738

38-
EXPOSE 8080
39+
EXPOSE 8888
3940
# Run
4041
WORKDIR /app
4142
CMD ["./depositor"]

docker-compose.yaml

Whitespace-only changes.

main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import (
2424
// @description Rest API for communication between SciCat frontend and depositor backend. Backend service enables deposition of datasets to OneDep API.
2525

2626
var version string = "DEV"
27-
var PORT string = getEnv("PORT", "8080")
28-
var ALLOW_ORIGINS string = getEnv("ALLOW_ORIGINS", "http://localhost:4202")
27+
var PORT string = getEnv("PORT", "8888")
28+
var ALLOW_ORIGINS string = getEnv("ALLOW_ORIGINS", "http://localhost:4200")
2929

3030
func getEnv(key, defaultValue string) string {
3131
if value, exists := os.LookupEnv(key); exists {
@@ -677,7 +677,7 @@ func GetVersion(c *gin.Context) {
677677
c.JSON(http.StatusOK, gin.H{"version": version})
678678
}
679679
func main() {
680-
680+
fmt.Println(ALLOW_ORIGINS, PORT)
681681
router := gin.Default()
682682
router.Use(cors.New(cors.Config{
683683
AllowOrigins: []string{ALLOW_ORIGINS},
@@ -697,5 +697,5 @@ func main() {
697697
router.POST("/onedep/metadata", DownloadMetadata)
698698
router.POST("/onedep/pdb", DownloadCoordinatesWithMetadata)
699699

700-
router.Run("localhost:" + PORT)
700+
router.Run(":" + PORT)
701701
}

0 commit comments

Comments
 (0)