From 50ff8393ddd49f49fac793ac27f80eef8ceca42c Mon Sep 17 00:00:00 2001 From: Andrew Mayorov Date: Tue, 12 Jul 2022 14:47:04 +0300 Subject: [PATCH] TD-222: Reuse valitydev/action-deploy-docker@v2 (#16) * Sync Dockerfiles w/ valitydev/erlang-templates --- .github/workflows/build-and-push-image.yaml | 54 --------------------- .github/workflows/build-image.yaml | 43 ---------------- .github/workflows/build-image.yml | 21 ++++++++ .github/workflows/erlang-checks.yaml | 2 +- Dockerfile | 14 +++--- Dockerfile.dev | 12 +++-- 6 files changed, 37 insertions(+), 109 deletions(-) delete mode 100644 .github/workflows/build-and-push-image.yaml delete mode 100644 .github/workflows/build-image.yaml create mode 100644 .github/workflows/build-image.yml diff --git a/.github/workflows/build-and-push-image.yaml b/.github/workflows/build-and-push-image.yaml deleted file mode 100644 index b704a49..0000000 --- a/.github/workflows/build-and-push-image.yaml +++ /dev/null @@ -1,54 +0,0 @@ -name: Build and push Docker image -on: - push: - branches: [master] - -env: - REGISTRY: ghcr.io - -jobs: - build: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Log in to the Container registry - uses: docker/login-action@v1 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Construct tags / labels for an image - id: meta - uses: docker/metadata-action@v3 - with: - images: | - ${{ env.REGISTRY }}/${{ github.repository }} - tags: | - type=sha - - # https://docs.github.com/en/actions/learn-github-actions/workflow-commands-for-github-actions#setting-an-environment-variable - - name: Update environment variables - run: grep -v '^#' .env >> $GITHUB_ENV - - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - - - name: Setup Buildx - uses: docker/setup-buildx-action@v1 - - - name: Build and push Docker image - uses: docker/build-push-action@v2 - with: - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - platforms: linux/amd64,linux/arm64 - cache-from: type=gha - cache-to: type=gha,mode=max - build-args: | - OTP_VERSION=${{ env.OTP_VERSION }} - THRIFT_VERSION=${{ env.THRIFT_VERSION }} - SERVICE_NAME=${{ env.SERVICE_NAME }} diff --git a/.github/workflows/build-image.yaml b/.github/workflows/build-image.yaml deleted file mode 100644 index 5e525b7..0000000 --- a/.github/workflows/build-image.yaml +++ /dev/null @@ -1,43 +0,0 @@ -name: Build Docker image -on: - pull_request: - branches: ["*"] - -env: - REGISTRY: ghcr.io - -jobs: - build: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Construct tags / labels for an image - id: meta - uses: docker/metadata-action@v3 - with: - images: | - ${{ env.REGISTRY }}/${{ github.repository }} - tags: | - type=sha - - # https://docs.github.com/en/actions/learn-github-actions/workflow-commands-for-github-actions#setting-an-environment-variable - - name: Update environment variables - run: grep -v '^#' .env >> $GITHUB_ENV - - - name: Setup Buildx - uses: docker/setup-buildx-action@v1 - - - name: Build Docker image - uses: docker/build-push-action@v2 - with: - push: false - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max - build-args: | - OTP_VERSION=${{ env.OTP_VERSION }} - THRIFT_VERSION=${{ env.THRIFT_VERSION }} - SERVICE_NAME=${{ env.SERVICE_NAME }} diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml new file mode 100644 index 0000000..ff53b0e --- /dev/null +++ b/.github/workflows/build-image.yml @@ -0,0 +1,21 @@ +name: Build and publish Docker image + +on: + push: + branches: + - 'master' + - 'epic/**' + pull_request: + branches: ['**'] + +env: + REGISTRY: ghcr.io + +jobs: + build-push: + runs-on: ubuntu-latest + steps: + - uses: valitydev/action-deploy-docker@v2 + with: + registry-username: ${{ github.actor }} + registry-access-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/erlang-checks.yaml b/.github/workflows/erlang-checks.yaml index 0ef752b..4bb7abf 100644 --- a/.github/workflows/erlang-checks.yaml +++ b/.github/workflows/erlang-checks.yaml @@ -6,7 +6,7 @@ on: - 'master' - 'epic/**' pull_request: - branches: [ '**' ] + branches: ['**'] jobs: setup: diff --git a/Dockerfile b/Dockerfile index ee06622..ec0732d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,10 +2,10 @@ ARG OTP_VERSION # Build the release FROM docker.io/library/erlang:${OTP_VERSION} AS builder +SHELL ["/bin/bash", "-o", "pipefail", "-c"] # Install thrift compiler ARG THRIFT_VERSION - ARG TARGETARCH RUN wget -q -O- "https://github.com/valitydev/thrift/releases/download/${THRIFT_VERSION}/thrift-${THRIFT_VERSION}-linux-${TARGETARCH}.tar.gz" \ | tar -xvz -C /usr/local/bin/ @@ -16,8 +16,8 @@ COPY . /build/ # Build the release WORKDIR /build -RUN rebar3 compile -RUN rebar3 as prod release +RUN rebar3 compile && \ + rebar3 as prod release # Make a runner image FROM docker.io/library/erlang:${OTP_VERSION}-slim @@ -28,15 +28,15 @@ ARG SERVICE_NAME ENV CHARSET=UTF-8 ENV LANG=C.UTF-8 -# Expose SERVICE_NAME as env so CMD expands properly on start -ENV SERVICE_NAME=${SERVICE_NAME} - # Set runtime WORKDIR /opt/${SERVICE_NAME} COPY --from=builder /build/_build/prod/rel/${SERVICE_NAME} /opt/${SERVICE_NAME} +RUN echo "#!/bin/sh" >> /entrypoint.sh && \ + echo "exec /opt/${SERVICE_NAME}/bin/${SERVICE_NAME} foreground" >> /entrypoint.sh && \ + chmod +x /entrypoint.sh ENTRYPOINT [] -CMD /opt/${SERVICE_NAME}/bin/${SERVICE_NAME} foreground +CMD ["/entrypoint.sh"] EXPOSE 8022 diff --git a/Dockerfile.dev b/Dockerfile.dev index b2805aa..e4cfa53 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -1,13 +1,17 @@ ARG OTP_VERSION FROM docker.io/library/erlang:${OTP_VERSION} +SHELL ["/bin/bash", "-o", "pipefail", "-c"] +# Install thrift compiler ARG THRIFT_VERSION -ARG BUILDARCH - -RUN wget -q -O- "https://github.com/valitydev/thrift/releases/download/${THRIFT_VERSION}/thrift-${THRIFT_VERSION}-linux-${BUILDARCH}.tar.gz" \ +ARG TARGETARCH +RUN wget -q -O- "https://github.com/valitydev/thrift/releases/download/${THRIFT_VERSION}/thrift-${THRIFT_VERSION}-linux-${TARGETARCH}.tar.gz" \ | tar -xvz -C /usr/local/bin/ +# Set env ENV CHARSET=UTF-8 ENV LANG=C.UTF-8 -CMD /bin/bash + +# Set runtime +CMD ["/bin/bash"]