Skip to content

Commit ab54816

Browse files
committed
Update CI workflow to build and push Docker container
1 parent 994a228 commit ab54816

2 files changed

Lines changed: 68 additions & 31 deletions

File tree

.github/workflows/ci.yml

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,55 @@
11
name: CI
2-
run-name: Publicación de la pagina web
2+
run-name: Publicación de la pagina web como un contenedor Docker
3+
4+
# Trigger the workflow on push or merge
35
on:
46
push:
57
branches:
68
- master
9+
pull_request_target:
10+
types: closed
11+
branches:
12+
- master
13+
14+
concurrency:
15+
group: '${{ github.workflow }} @ ${{ github.event.issue.number || github.sha || github.head_ref || github.ref }}-${{ github.event.schedule || github.event.comment.id || github.event.sender.login }}'
16+
cancel-in-progress: true
17+
18+
permissions:
19+
contents: read
20+
packages: write
721

822
jobs:
9-
build:
23+
docker:
24+
if: ${{ github.event_name != 'pull_request_target' || github.event.pull_request.merged == true }}
1025
runs-on: ubuntu-latest
11-
environment: deploy
1226
steps:
13-
- name: Checkout the current branch
14-
uses: actions/checkout@v3
15-
16-
- name: Initialize the ssh-agent
17-
uses: webfactory/ssh-agent@v0.4.1
18-
with:
19-
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
20-
21-
- name: Create the docker image
22-
run: make init
23-
24-
- name: Build the website
25-
run: make build
26-
27-
- name: Scan the host key
28-
run: mkdir -p ~/.ssh/ && ssh-keyscan -p $DEPLOY_PORT -H $DEPLOY_SERVER >> ~/.ssh/known_hosts
29-
env:
30-
DEPLOY_SERVER: ${{ secrets.DEPLOY_SERVER }}
31-
DEPLOY_PORT: ${{ secrets.DEPLOY_PORT }}
32-
33-
- name: Deploy the website
34-
run: >-
35-
rsync -avx -e "ssh -p $DEPLOY_PORT" --delete --exclude '.ssh' public/ $DEPLOY_USERNAME@$DEPLOY_SERVER:$DEPLOY_PATH
36-
env:
37-
DEPLOY_SERVER: ${{ secrets.DEPLOY_SERVER }}
38-
DEPLOY_PORT: ${{ secrets.DEPLOY_PORT }}
39-
DEPLOY_USERNAME: ${{ secrets.DEPLOY_USERNAME }}
40-
DEPLOY_PATH: ${{ secrets.DEPLOY_PATH }}
27+
- uses: actions/checkout@v4
28+
29+
- name: Downcase REPO variable
30+
run: |
31+
# Lowercase repository identifier (bash expansion)
32+
echo "REPO=${GITHUB_REPOSITORY,,}" >> "${GITHUB_ENV}"
33+
34+
- name: Set up QEMU
35+
uses: docker/setup-qemu-action@v3
36+
37+
- name: Set up Docker Buildx
38+
uses: docker/setup-buildx-action@v3
39+
40+
- name: Log in to ghcr
41+
uses: docker/login-action@v3
42+
with:
43+
registry: ghcr.io
44+
username: ${{ github.actor }}
45+
password: ${{ secrets.GITHUB_TOKEN }}
46+
47+
- name: Build and push
48+
uses: docker/build-push-action@v5
49+
with:
50+
push: true
51+
tags: |
52+
ghcr.io/${{ env.REPO }}:${{ github.ref_name }}
53+
ghcr.io/${{ env.REPO }}:${{ github.sha }}
54+
platforms: linux/amd64
55+

Dockerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
ARG HUGO_VERSION=0.62.2
2+
FROM registry.gitlab.com/pages/hugo/hugo_extended:${HUGO_VERSION} AS builder
3+
4+
RUN sed -i'' -e 's/edge/v3.12/g' /etc/apk/repositories && \
5+
apk --quiet --no-progress --update --allow-untrusted -X https://dl-cdn.alpinelinux.org/alpine/v3.12/main add alpine-keys && \
6+
apk --quiet --no-progress update && \
7+
apk --quiet --no-progress --no-cache add make git
8+
9+
WORKDIR /src
10+
COPY . .
11+
12+
RUN git submodule update --init --recursive || true
13+
RUN hugo
14+
15+
FROM nginx:alpine
16+
17+
COPY --from=builder /src/public /usr/share/nginx/html
18+
19+
# Expose port 80
20+
EXPOSE 80
21+
22+
CMD ["nginx", "-g", "daemon off;"]

0 commit comments

Comments
 (0)