diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..2334c10 --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,38 @@ +name: Publish Docker image + +on: + release: + types: [published] + workflow_dispatch: + +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: Log in to Docker Hub + uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + with: + images: ${{ github.repository }} + + - name: Copy Dockerfile to the root of the repository + shell: bash + run: cp ./docker/Dockerfile . + + - name: Build and push Docker image + uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/docker/Dockerfile b/docker/Dockerfile index e309a53..b98eec8 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,9 +1,5 @@ FROM node:14-alpine3.12 -# Read the GitHub API token and release version from --build-arg -ARG GITHUB_API_TOKEN -ARG VERSION - # Install dependencies not included in the base image RUN apk update RUN apk upgrade @@ -27,6 +23,6 @@ RUN chmod +x dist/bin/* RUN yarn link # Set the entrypoint and main command -# Runs the bot by default, but CMD can be overriden when running a container so it runs the reactions monitor server +# Runs the default Infura gateway, but CMD can be overriden when running a container so it runs the reactions monitor server ENTRYPOINT ["npx"] CMD ["w3gw-infura"] diff --git a/docker/downloader.sh b/docker/downloader.sh deleted file mode 100644 index 1a3c37c..0000000 --- a/docker/downloader.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env bash - -# Read from the environment the which version to download -# Defaults to "latest" -VERSION=${VERSION:-"latest"} - -# A helper function for scoped logging -function log { - echo "[DOWNLOADER] $1" -} - -# Make sure that `GITHUB_API_TOKEN` is defined -if [[ -z "$GITHUB_API_TOKEN" ]]; then - log "Missing GITHUB_API_TOKEN environment variable" - exit 1 -fi - -AUTH="Authorization: token $GITHUB_API_TOKEN" - -# If version is "latest", resolve the latest version number -if [[ "$VERSION" == "latest" ]]; then - VERSION=$(curl --cacert /etc/ssl/certs/ca-certificates.crt -H "$AUTH" https://api.github.com/repos/witnet/web3-jsonrpc-gateway/releases/latest | sed -En "s/.*\"tag_name\": \"([0-9|\.]+)\",/\1/p" | head -1) -fi - -# The URL of the release file, and the name that will be used when downloaded -URL="https://api.github.com/repos/witnet/web3-jsonrpc-gateway/tarball/$VERSION" -FILENAME="release.tar.gz" - -# Download and extract release bundle -log "Downloading version $VERSION ('$FILENAME') from '$URL'. This may take a few seconds..." -curl --cacert /etc/ssl/certs/ca-certificates.crt -LH "$AUTH" -o "/tmp/$FILENAME" "$URL" && -tar -zxf "/tmp/$FILENAME" --directory "/tmp/" && -mv /tmp/witnet-web3-jsonrpc-gateway-* /data/source && -# Clean after ourselves -rm -f "/tmp/$FILENAME" && -# Show success or error message -log "Succesfully downloaded and extracted '$FILENAME'" || -log "Error downloading and installing version $VERSION" \ No newline at end of file