Skip to content

Commit

Permalink
Build docker images on github actions (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmj authored Jan 13, 2025
1 parent cb3dc75 commit 7eaf7c1
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 53 deletions.
47 changes: 45 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
env:
MIX_ENV: test
steps:
Expand All @@ -13,11 +13,54 @@ jobs:
- uses: erlef/setup-elixir@v1
with:
otp-version: 27.2
elixir-version: 1.17.3
elixir-version: 1.18.1

- run: mix deps.get
- run: mix deps.compile
- run: mix compile --warnings-as-errors
- run: mix test
- run: mix format --check-formatted
- run: mix deps.unlock --check-unused

docker:
name: Docker
runs-on: ubuntu-24.04
permissions:
contents: 'read'
id-token: 'write'
env:
IMAGE_NAME: 'preview'
PROJECT_ID: 'hexpm-prod'
SERVICE_ACCOUNT: ${{ secrets.GCLOUD_SERVICE_ACCOUNT }}
WORKLOAD_IDENTITY_PROVIDER: ${{ secrets.GCLOUD_WORKFLOW_IDENTITY_POOL_PROVIDER }}
steps:
- uses: actions/checkout@v4
- name: Set short git commit SHA
id: vars
run: |
calculatedSha=$(git rev-parse --short ${{ github.sha }})
echo "COMMIT_SHORT_SHA=$calculatedSha" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Google auth
id: auth
uses: 'google-github-actions/auth@v2'
with:
token_format: 'access_token'
project_id: ${{ env.PROJECT_ID }}
service_account: ${{ env.SERVICE_ACCOUNT }}
workload_identity_provider: ${{ env.WORKLOAD_IDENTITY_PROVIDER }}
- name: Docker Auth
id: docker-auth
uses: 'docker/login-action@v3'
with:
registry: gcr.io
username: 'oauth2accesstoken'
password: '${{ steps.auth.outputs.access_token }}'
- name: Build and push
uses: docker/build-push-action@v6
with:
tags: gcr.io/${{ env.PROJECT_ID }}/${{ env.IMAGE_NAME }}:${{ env.COMMIT_SHORT_SHA }}
push: ${{ github.event_name != 'pull_request' }}
cache-from: type=gha
cache-to: type=gha,mode=max
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ARG ELIXIR_VERSION=1.17.3
ARG ELIXIR_VERSION=1.18.1
ARG ERLANG_VERSION=27.2
ARG DEBIAN_VERSION=bookworm-20241202-slim
ARG DEBIAN_VERSION=bookworm-20241223-slim

FROM hexpm/elixir:${ELIXIR_VERSION}-erlang-${ERLANG_VERSION}-debian-${DEBIAN_VERSION} AS build

Expand Down
48 changes: 0 additions & 48 deletions cloudbuild.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule Preview.MixProject do
[
app: :preview,
version: "0.1.0",
elixir: "~> 1.17",
elixir: "~> 1.18",
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
aliases: aliases(),
Expand Down

0 comments on commit 7eaf7c1

Please sign in to comment.