diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..9fc7b1c --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,45 @@ +name: Docker Image CI + +on: + push: + branches: ["main"] + pull_request: + branches: ["main"] + schedule: + - cron: "30 12 * * 0" # Run once every Sunday + +jobs: + push_to_registry: + name: Push Docker image to Docker Hub + runs-on: ubuntu-latest + steps: + - name: Check out the repo + uses: actions/checkout@v3 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ secrets.DOCKER_USERNAME }}/ultraviolet-node + tags: | + type=raw,value={{date 'YYYYMMDD'}} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build & push Docker image + uses: docker/build-push-action@v3 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ secrets.DOCKER_USERNAME }}/ultraviolet-node:latest,${{ steps.meta.outputs.tags }} diff --git a/Dockerfile b/Dockerfile index 6924afe..e0e0c27 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,19 @@ -FROM node:current-slim +# build app +FROM docker.io/node AS builder +RUN apt update +RUN apt install git + +COPY . /app WORKDIR /app -COPY ./package.json ./package-lock.json ./src/ ./ +RUN npm install -RUN npm install --omit=dev +# build final +FROM gcr.io/distroless/nodejs:16 -ENTRYPOINT npm start +EXPOSE 8080/tcp + +COPY --from=builder /app / + +CMD ["src/index.js"] \ No newline at end of file