From f06e833cf07631e276f809e52ccc2baca81ad656 Mon Sep 17 00:00:00 2001 From: Neur0toxine Date: Fri, 13 Oct 2023 15:07:50 +0300 Subject: [PATCH] dockerization --- .github/dependabot.yml | 6 +++ .github/workflows/buildx.yml | 93 ++++++++++++++++++++++++++++++++++++ Dockerfile | 17 +++++++ go.mod | 2 +- 4 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/buildx.yml create mode 100644 Dockerfile diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..1230149 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" diff --git a/.github/workflows/buildx.yml b/.github/workflows/buildx.yml new file mode 100644 index 0000000..1c6a5dd --- /dev/null +++ b/.github/workflows/buildx.yml @@ -0,0 +1,93 @@ +name: buildx + +on: + pull_request: + push: + +jobs: + buildx: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + docker-file: + - path: latest + tags: "latest" + platforms: linux/amd64,linux/arm64 + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Prepare + id: prepare + run: | + DOCKER_IMAGE=neur0toxine/wa-profile-api + + TEMP="${{ matrix.docker-file.tags }}" + TAGZ=($TEMP) + VERSION=${TAGZ[0]} + + for i in "${!TAGZ[@]}"; do + if [ "$i" -eq "0" ]; + then + TAGS="${DOCKER_IMAGE}:${TAGZ[$i]}" + else + TAGS="${TAGS},${DOCKER_IMAGE}:${TAGZ[$i]}" + fi + done + + echo ::set-output name=docker_image::${DOCKER_IMAGE} + echo ::set-output name=version::${VERSION} + echo ::set-output name=tags::${TAGS} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3.0.0 + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v3.0.0 + with: + install: true + + - name: Available platforms + run: echo ${{ steps.buildx.outputs.platforms }} + + - name: Docker Buildx (build) + uses: docker/build-push-action@v5.0.0 + if: success() && !contains(github.ref, 'master') + with: + push: false + context: ./${{ matrix.docker-file.path }} + file: ./${{ matrix.docker-file.path }}/Dockerfile + build-args: REFRESHED_AT=$(date +%Y-%m-%d) + platforms: ${{ matrix.docker-file.platforms }} + tags: ${{ steps.prepare.outputs.tags }} + + - name: Docker Login + if: success() && contains(github.ref, 'master') + uses: docker/login-action@v3.0.0 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Docker Buildx (push) + uses: docker/build-push-action@v5.0.0 + if: success() && contains(github.ref, 'master') + with: + push: true + context: ./${{ matrix.docker-file.path }} + file: ./${{ matrix.docker-file.path }}/Dockerfile + build-args: REFRESHED_AT=$(date +%Y-%m-%d) + platforms: ${{ matrix.docker-file.platforms }} + tags: ${{ steps.prepare.outputs.tags }} + + - name: Inspect Image + if: always() && github.event_name != 'pull_request' && contains(github.ref, 'master') + run: | + docker buildx imagetools inspect ${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }} + + - name: Clear + if: always() && github.event_name != 'pull_request' + run: | + rm -f ${HOME}/.docker/config.json diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..18d2dd8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM golang:1.21-alpine AS builder +WORKDIR /build +COPY ./ /build/ +RUN apk update && \ + apk add --no-cache ca-certificates tzdata make bash && \ + update-ca-certificates && \ + go version && \ + cd /build && \ + make build + +FROM scratch +WORKDIR / +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt +COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo +COPY --from=builder /build/wa-profile-api /wa-profile-api +EXPOSE 8090 +ENTRYPOINT ["/wa-profile-api"] diff --git a/go.mod b/go.mod index d4f9c1d..4d9f445 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/Neur0toxine/wa-profile-api -go 1.21.2 +go 1.21.3 require ( github.com/go-playground/validator/v10 v10.15.5