diff --git a/.gitignore b/.gitignore index 4fa932f..205c8d8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .env .botenv api-server +ssh diff --git a/Dockerfile b/Dockerfile index 53d55b3..77cd073 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,22 +6,26 @@ COPY . . RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o api-server . FROM alpine:latest -RUN apk --no-cache add git ca-certificates jq curl +RUN apk --no-cache add git ca-certificates jq curl openssh WORKDIR /app -COPY --from=builder /app/api-server . +COPY --from=builder --chown=1000:1000 /app/api-server . + +RUN addgroup -g 1000 appuser && \ + adduser -D -u 1000 -G appuser appuser + RUN printf '#!/bin/sh\n\n' > /entrypoint.sh && \ - printf 'if [ -n "$GIT_USERNAME" ] && [ -n "$GITHUB_TOKEN" ]; then\n' >> /entrypoint.sh && \ - printf ' git config --global user.name "$GIT_USERNAME"\n' >> /entrypoint.sh && \ - printf ' git config --global user.email "${GIT_EMAIL:-no-reply@example.com}"\n' >> /entrypoint.sh && \ + # printf 'if [ -n "$GIT_USERNAME" ] && [ -n "$FORGEJO_TOKEN" ]; then\n' >> /entrypoint.sh && \ + printf ' git config --global user.name "AlaskarTV-Bot"\n' >> /entrypoint.sh && \ + printf ' git config --global user.email "no-reply@askar.tv}"\n' >> /entrypoint.sh && \ printf ' git config --global credential.helper store\n' >> /entrypoint.sh && \ - printf ' echo "https://${GIT_USERNAME}:${GITHUB_TOKEN}@github.com" > /root/.git-credentials\n' >> /entrypoint.sh && \ - printf ' chmod 600 /root/.git-credentials\n' >> /entrypoint.sh && \ - printf 'fi\n\n' >> /entrypoint.sh && \ - # Add safe directories - printf 'git config --global --add safe.directory /data/alaskartv/docker-ci\n' >> /entrypoint.sh && \ - printf 'git config --global --add safe.directory /data/alaskartv/androidtv-ci\n\n' >> /entrypoint.sh && \ + # printf ' echo "https://${GIT_USERNAME}:${FORGEJO_TOKEN}@git.askar.tv" > /root/.git-credentials\n' >> /entrypoint.sh && \ + # printf ' chmod 600 /root/.git-credentials\n' >> /entrypoint.sh && \ + # printf 'fi\n\n' >> /entrypoint.sh && \ + # # Add safe directories + printf 'git config --global --add safe.directory /data/alaskartv-forge/alaskartv-docker\n' >> /entrypoint.sh && \ + printf 'git config --global --add safe.directory /data/alaskartv-forge/alaskartv-app\n\n' >> /entrypoint.sh && \ # Finally, run the main app printf 'crond -b\n' >> /entrypoint.sh && \ printf 'exec /app/api-server\n' >> /entrypoint.sh && \ @@ -33,5 +37,6 @@ COPY .botenv /app/.botenv RUN chmod +x /app/watchTV.sh && \ echo "0 0 * * * /app/watchTV.sh" > /etc/crontabs/root +USER appuser ENTRYPOINT ["/entrypoint.sh"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..055cd45 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +Mount repos on /data/alaskartv-??/ +Mount ssh key on appuser/.ssh diff --git a/docker-compose.yml b/docker-compose.yml index af9a950..ed480e3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,14 +1,11 @@ services: api-server: - image: nomadics/api-server:latest + image: nomadics/api-forge:latest container_name: api-server ports: - - "9090:8080" - environment: - - GIT_USERNAME=${GIT_USERNAME} - - GIT_EMAIL=${GIT_EMAIL} - - GITHUB_TOKEN=${GITHUB_TOKEN} + - "9999:8080" volumes: - - ~/alaskartv:/data/alaskartv + - ~/alaskartv-forge:/data/alaskartv-forge + - ~/.ssh/:/home/appuser/.ssh restart: unless-stopped hostname: alaskar-api diff --git a/main.go b/main.go index 0a19b7f..e87c6d7 100644 --- a/main.go +++ b/main.go @@ -197,7 +197,7 @@ func main() { })) router.POST("/api/alaskarfin", func(c *gin.Context) { - jsonResponse, err := updateVersion("/data/alaskartv/docker-ci/alaskarfin", "alaskarfin") + jsonResponse, err := updateVersion("/data/alaskartv-forge/alaskartv-docker/alaskarfin", "alaskarfin") if err != nil { c.JSON(http.StatusInternalServerError, gin.H{ "error": err.Error(), @@ -210,7 +210,7 @@ func main() { }) router.POST("/api/alaskarseer", func(c *gin.Context) { - jsonResponse, err := updateVersion("/data/alaskartv/docker-ci/alaskarseer", "alaskarseer") + jsonResponse, err := updateVersion("/data/alaskartv-forge/alaskartv-docker/alaskarseer", "alaskarseer") if err != nil { c.JSON(http.StatusInternalServerError, gin.H{ "error": err.Error(), @@ -223,7 +223,7 @@ func main() { }) router.POST("/api/alaskartv", func(c *gin.Context) { - jsonResponse, err := updateVersion("/data/alaskartv/androidtv-ci", "alaskartv") + jsonResponse, err := updateVersion("/data/alaskartv-forge/alaskartv-app", "alaskartv") if err != nil { c.JSON(http.StatusInternalServerError, gin.H{ "error": err.Error(),