From a7d2ffa8f3c40c53ece1c57798c94b2242b586e8 Mon Sep 17 00:00:00 2001 From: Wilfried OLLIVIER Date: Sun, 28 Jul 2024 22:21:09 +0200 Subject: [PATCH] chore: Migrate CI from Drone to Github Actions (#15) --- .github/workflows/elixir.yml | 28 ----------- .github/workflows/main.yml | 94 ++++++++++++++++++++++++++++++++++++ Dockerfile | 24 +++------ build/ci/drone.yml | 41 ---------------- 4 files changed, 100 insertions(+), 87 deletions(-) delete mode 100644 .github/workflows/elixir.yml create mode 100644 .github/workflows/main.yml delete mode 100644 build/ci/drone.yml diff --git a/.github/workflows/elixir.yml b/.github/workflows/elixir.yml deleted file mode 100644 index 630bfea..0000000 --- a/.github/workflows/elixir.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: Build & Test - -on: - push: - branches: - - master - tags: - - '*' - pull_request: - branches: - - "master" - -jobs: - build: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up Elixir - uses: erlef/setup-beam@61e01a43a562a89bfc54c7f9a378ff67b03e4a21 # v1.16.0 - with: - elixir-version: '1.17' # [Required] Define the Elixir version - - name: Install dependencies - run: mix deps.get - - - name: Build - run: mix compile diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..04ca978 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,94 @@ +name: Build & Test + +on: + push: + branches: + - master + tags: + - '*' + pull_request: + branches: + - "master" + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Elixir + uses: erlef/setup-beam@61e01a43a562a89bfc54c7f9a378ff67b03e4a21 # v1.16.0 + with: + elixir-version: '1.17' + otp-version: '26.0' + + - name: Install dependencies + run: mix deps.get + + - name: Build + run: mix compile + + test: + needs: build + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Elixir + uses: erlef/setup-beam@61e01a43a562a89bfc54c7f9a378ff67b03e4a21 # v1.16.0 + with: + elixir-version: '1.17' + otp-version: '26.0' + + - name: Install dependencies + run: mix deps.get + + - name: Test + run: mix test --no-start + + container: + runs-on: ubuntu-latest + needs: test + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Setup Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Resolve image tag + id: tag + run: | + if [[ "${{ github.ref }}" =~ "refs/tags/" ]]; then + TAG=${{ github.ref_name }} + else + TAG="latest" + fi + echo "TAG=${TAG}" >> $GITHUB_ENV + + - name: Build and push Docker image + uses: docker/build-push-action@v6 + with: + push: true + tags: papey/o2m:${{ env.TAG }} + labels: | + org.opencontainers.image.source=${{ github.event.repository.clone_url }} + org.opencontainers.image.url=${{ github.event.repository.html_url }} + org.opencontainers.image.revision=${{ github.sha }} + org.opencontainers.image.version=${{ env.TAG }} + org.opencontainers.image.authors="Wilfried OLLIVIER" + org.opencontainers.image.title="trostani" + org.opencontainers.image.description=${{ github.event.repository.description }} + org.opencontainers.image.licences="Unlicense" diff --git a/Dockerfile b/Dockerfile index 6c70858..948d5c8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,23 +4,9 @@ FROM elixir:1.17 as builder RUN apt-get update && apt-get install -y openssl -# Declare args -ARG REVISION -ARG RELEASE_TAG - # Ensure mix is in prod mode ENV MIX_ENV=prod -# image-spec annotations using labels -# https://github.com/opencontainers/image-spec/blob/master/annotations.md -LABEL org.opencontainers.image.source="https://github.com/papey/o2m" -LABEL org.opencontainers.image.revision=${GIT_COMMIT_SHA} -LABEL org.opencontainers.image.version=${RELEASE_TAG} -LABEL org.opencontainers.image.authors="Wilfried OLLIVIER" -LABEL org.opencontainers.image.title="o2m" -LABEL org.opencontainers.image.description="o2m runtime" -LABEL org.opencontainers.image.licences="Unlicense" - # Create src dir RUN mkdir /opt/o2m @@ -52,11 +38,8 @@ RUN apt-get update -y \ && apt-get install -y openssl \ libtinfo-dev \ ffmpeg \ - python3 \ - python3-pip + pipx -# Install latest yt-dlp from github -RUN pip3 install yt-dlp # Copy over the build artifact from the previous step and create a non root user RUN useradd o2m @@ -74,6 +57,11 @@ RUN chown -R o2m:o2m ./prod USER o2m +# Install latest yt-dlp from github +RUN pipx install yt-dlp + +ENV PATH="${HOME}/.local/bin:${PATH}" + # default arg CMD ["start"] diff --git a/build/ci/drone.yml b/build/ci/drone.yml deleted file mode 100644 index 774a11c..0000000 --- a/build/ci/drone.yml +++ /dev/null @@ -1,41 +0,0 @@ -kind: pipeline -name: main - -steps: - - name: compile - image: elixir:1.17 - commands: - - mix local.hex --force - - mix local.rebar --force - - mix deps.get - - mix compile - - - name: tests - image: elixir:1.17 - environment: - DISCORD_TOKEN: - from_secret: discord_token - O2M_FEED_URLS: - from_secret: o2m_feed_urls - 02M_CHAN_ID: - from_secret: o2m_chan_id - O2M_GUILD_ID: - from_secret: o2m_guild_id - commands: - - mix local.hex --force - - mix local.rebar --force - - mix deps.get - - mix test --no-start - - - name: docker - image: plugins/docker - settings: - username: - from_secret: docker_username - password: - from_secret: docker_password - repo: papey/o2m - auto_tag: true - build_args: - - REVISION=$$CI_COMMIT - - RELEASE_TAG=$$CI_TAG