Skip to content

Commit

Permalink
Merge pull request #273 from jonfairbanks/fixes/clean-up
Browse files Browse the repository at this point in the history
Update Docker caching method
  • Loading branch information
jonfairbanks authored Nov 25, 2024
2 parents 1ca81e6 + 8d3be4e commit 123f179
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
38 changes: 27 additions & 11 deletions .github/workflows/docker-build-develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ jobs:
id: buildx
uses: docker/setup-buildx-action@v3

- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache/${{ runner.os }}-${{ steps.setup-buildx.outputs.name }}-${{ hashFiles('**/Dockerfile') }}
key: ${{ runner.os }}-buildx-${{ steps.vars.outputs.sha_short }}-{{ hashFiles('**/Dockerfile') }}
restore-keys: |
${{ runner.os }}-buildx-
# - name: Cache Docker layers
# uses: actions/cache@v4
# with:
# path: /tmp/.buildx-cache/${{ runner.os }}-${{ steps.setup-buildx.outputs.name }}-${{ hashFiles('**/Dockerfile') }}
# key: ${{ runner.os }}-buildx-${{ steps.vars.outputs.sha_short }}-{{ hashFiles('**/Dockerfile') }}
# restore-keys: |
# ${{ runner.os }}-buildx-

- name: Login to DockerHub
uses: docker/login-action@v3
Expand All @@ -116,21 +116,37 @@ jobs:
uses: aws-actions/amazon-ecr-login@v2
with:
mask-password: 'true'

- name: Get Repository Name
id: repo-name
run: echo "REPO_NAME=$(basename $GITHUB_REPOSITORY)" >> $GITHUB_ENV

- name: Create ECR Repository if not exists
env:
AWS_REGION: us-east-1
REPO_NAME: ${{ env.REPO_NAME }}
run: |
aws ecr describe-repositories --repository-names $REPO_NAME --region $AWS_REGION || \
aws ecr create-repository --repository-name $REPO_NAME --region $AWS_REGION

- name: Build & Push Docker image(s)
id: docker-build
uses: docker/build-push-action@v6
with:
builder: ${{ steps.buildx.outputs.name }}
context: ./src
platforms: linux/amd64,linux/arm64
platforms: linux/amd64 # TODO: Re-add `linux/arm64`
file: ./src/Dockerfile
push: true
provenance: false
tags: |
${{ github.repository }}:develop
${{ steps.ecr-login.outputs.registry }}/yo-api:develop
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
${{ steps.ecr-login.outputs.registry }}/jonfairbanks/yo-api:develop
# cache-from: type=local,src=/tmp/.buildx-cache
# cache-to: type=local,dest=/tmp/.buildx-cache
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Notify Slack
uses: act10ns/slack@v2
Expand Down
2 changes: 1 addition & 1 deletion src/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ FROM node:20 AS production
ENV TERM=xterm
WORKDIR /app
COPY --from=build /app .
RUN npm install --production
RUN npm install --omit=dev
EXPOSE 3000
CMD ["npm", "run", "start"]

0 comments on commit 123f179

Please sign in to comment.