Skip to content

Commit

Permalink
update build docker action
Browse files Browse the repository at this point in the history
  • Loading branch information
nemanjam committed May 15, 2024
1 parent d5912b8 commit b4afa1b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 29 deletions.
24 changes: 14 additions & 10 deletions .github/workflows/build-push-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:
env:
IMAGE_NAME: ${{ github.repository }}
# set this
SITE_URL: 'https://nemanjamitic.com'
SITE_URL: 'https://docker.nemanjamitic.com'

jobs:
build:
Expand All @@ -33,8 +33,10 @@ jobs:
echo "github.ref -> {{ github.ref }}"
- name: Docker metadata
# disable this step
if: false
id: metadata
uses: docker/metadata-action@v3
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME }}
tags: |
Expand All @@ -43,19 +45,21 @@ jobs:
type=raw,value={{sha}},enable=${{ github.ref_type != 'tag' }}
- name: Log in to Docker Hub
uses: docker/login-action@v1
if: ${{ github.ref_type == 'tag' }}
uses: docker/login-action@v3
# if: ${{ github.ref_type == 'tag' }}
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push Docker image
uses: docker/build-push-action@v2
uses: docker/build-push-action@v5
with:
context: ./apps/nemanjamiticcom/

# build app is in Dockerfile
# src dir
context: ./
# Dockerfile dir
file: ./docker/Dockerfile
push: true
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:latest
# disabled metadata step
# tags: ${{ steps.metadata.outputs.tags }}
# labels: ${{ steps.metadata.outputs.labels }}
17 changes: 10 additions & 7 deletions .github/workflows/deploy-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ on:

workflow_dispatch:

env:
IMAGE_NAME_WITH_TAG: ${{ secrets.DOCKERHUB_USERNAME }}/${{ github.repository }}

jobs:
deploy:
name: Deploy image from Dockerhub to remote host with ssh
runs-on: ubuntu-latest

steps:
- name: Deploy latest image
uses: appleboy/ssh-action@master
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.REMOTE_HOST }}
username: ${{ secrets.REMOTE_USERNAME }}
Expand All @@ -25,17 +28,17 @@ jobs:
script: |
cd /home/ubuntu/traefik-proxy/apps/nmc-docker
echo "Old image tag: $(docker inspect --format '{{ index .RepoTags 0 }}' nemanjamitic/nemanjamiticcom)"
echo "Old image hash: $(docker inspect --format '{{ index .RepoDigests 0 }}' nemanjamitic/nemanjamiticcom)"
echo "Old image tag: $(docker inspect --format '{{ index .RepoTags 0 }}' ${{ env.IMAGE_NAME_WITH_TAG }})"
echo "Old image hash: $(docker inspect --format '{{ index .RepoDigests 0 }}' ${{ env.IMAGE_NAME_WITH_TAG }})"
docker-compose down
docker image rm nemanjamitic/nemanjamiticcom:latest
docker image rm ${{ env.IMAGE_NAME_WITH_TAG }}
docker-compose up -d
echo "New image tag: $(docker inspect --format '{{ index .RepoTags 0 }}' nemanjamitic/nemanjamiticcom)"
echo "New image hash: $(docker inspect --format '{{ index .RepoDigests 0 }}' nemanjamitic/nemanjamiticcom)"
echo "New image tag: $(docker inspect --format '{{ index .RepoTags 0 }}' ${{ env.IMAGE_NAME_WITH_TAG }})"
echo "New image hash: $(docker inspect --format '{{ index .RepoDigests 0 }}' ${{ env.IMAGE_NAME_WITH_TAG }})"
# remove dangling images, optional
docker image prune -af
# docker image prune -af
2 changes: 1 addition & 1 deletion .github/workflows/deploy-nginx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
ls -la
- name: Copy dist folder to remote host
uses: appleboy/scp-action@master
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.REMOTE_HOST }}
username: ${{ secrets.REMOTE_USERNAME }}
Expand Down
20 changes: 9 additions & 11 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
# Dockerfile from Astro docs

FROM node:20.10.0-slim AS base
ARG NODE_VERSION=20.13.1

FROM node:${NODE_VERSION}-alpine AS base
WORKDIR /app

FROM base AS build
COPY package.json yarn.lock ./

FROM base AS prod-deps
RUN yarn install --production

FROM base AS build-deps
RUN yarn install --production=false

FROM build-deps AS build
RUN yarn install --frozen-lockfile
COPY . .
RUN yarn build

FROM nginx:stable-alpine3.17-slim AS runtime
COPY ./docker/nginx.conf /etc/nginx/nginx.conf
COPY --from=prod-deps /app/node_modules /usr/share/nginx/html/node_modules

# sufficient for SSG
COPY --from=build /app/dist /usr/share/nginx/html
EXPOSE 8080
EXPOSE 8080

0 comments on commit b4afa1b

Please sign in to comment.